想用console.log()在调试器中显示number的值但一直显示undefined,哪里有误?
[图片][图片][图片] 调试器第一个返回的是第25行的res,第二个是第四十四行的number,返回值的是undefined,我想看一下number经过赋值后的值,如果顺利的话number的值应该为1,请问各位大神我哪里出错了,谢谢 const devicesId = "654415117" // 填写在OneNet上获得的devicesId 形式就是一串数字 例子:9939133 const api_key = "buI7HCwy8AJ6alYtSUVafNzozDs=" // 填写在OneNet上的 api-key 例子: VeFI0HZ44Qn5dZO14AuLbWSlSlI= Page({ data: { asd:' ' }, getDatapoints: function () { return new Promise((resolve, reject) => { wx.request({ url: `https://api.heclouds.com/devices/${devicesId}/datapoints?datastream_id=Number&limit=1`, /** * 添加HTTP报文的请求头, * 其中api-key为OneNet的api文档要求我们添加的鉴权秘钥 * Content-Type的作用是标识请求体的格式, 从api文档中我们读到请求体是json格式的 * 故content-type属性应设置为application/json */ header: { 'content-type': 'application/json', 'api-key': api_key }, success: (res) => { console.log(res.data) const status = res.statusCode const response = res.data if (status !== 200) { // 返回状态码不为200时将Promise置为reject状态 reject(res.data) return ; } if (response.errno !== 0) { //errno不为零说明可能参数有误, 将Promise置为reject reject(response.error) return ; } if (response.data.datastreams.length === 0) { reject("当前设备无数据, 请先运行硬件实验") } //程序可以运行到这里说明请求成功, 将Promise置为resolve状态 resolve({ number: response.data.datastreams[0].datapoints[0].value, // light: response.data.datastreams[1].datapoints.reverse(), }) console.log(resolve.number) }, fail: (err) => { reject(err) } }) }) }, })