8***@qq.com
8***@qq.com
  • 发布:2022-09-02 09:05
  • 更新:2023-06-06 00:52
  • 阅读:142

uniapp vue2中跑阿里物联网api出现问题,在Node项目中就没有问题,不知道为什么

分类:uni-app

nodejs测试代码:

const Core = require('@alicloud/pop-core');  

var client = new Core({  
  accessKeyId: 'LTAI5t6SEt9sbKh8arSW88PR',  
  accessKeySecret: 'HW2PB7pm5jOSfJX3IIaKfPnTejtUGE',  
  // securityToken: '<your-sts-token>', // use STS Token  
  endpoint: 'https://iot.cn-shanghai.aliyuncs.com',  
  apiVersion: '2018-01-20'  
});  

var params = {  
  "Items": "{\"temperature\":77777}",  
  "DeviceName": "mqttSimulator",  
  "ProductKey": "hl46zLyhuQC",  
  "IotInstanceId": "iot-06z00ezzxzvv6c8"  
}  

var requestOption = {  
  method: 'POST',  
  formatParams: false,  

};  

client.request('SetDeviceProperty', params, requestOption).then((result) => {  
  console.log(JSON.stringify(result));  
}, (ex) => {  
  console.log(ex);  
})

上面的代码在vscode和hbuilderX上的node项目中跑都不会有任何问题,但是在uniapp vue2项目,自建按钮跑是就爆出问题:

"message": "Cannot read property 'getHeaders' of undefined",
"stack": "TypeError: Cannot read property 'getHeaders' of undefined\n at http://localhost:8080/static/js/pages-index-index.js:32870:33\n at <anonymous>"

不知道问题出在哪了?

2022-09-02 09:05 负责人:无 分享
已邀请:
a***@yoshino.fun

a***@yoshino.fun

同问,不知道问题在哪

要回复问题请先登录注册