promise 返回数据是以下格式 怎么转换成以点取值的数据呢?
- Promise {<pending>}
- __proto__: Promise
- [[PromiseStatus]]: "resolved"
- [[PromiseValue]]: Object
- code: 200
- data: 1130
- message: "success"
- __proto__: Object
怎么把object的数据转换
请求方法
const request = (url, options) => {
return new Promise((resolve, reject) => {
wx.request({
url: `${host}${url}`,
method: options.method,
data: options.method === 'POST' ? options.data : JSON.stringify(options.data),
header: {
'content-type': 'application/json; charset=UTF-8',
'token': token,
},
success(request) {
if (request.data.code === 200) {
resolve(request.data)
} else {
reject(request.data)
}
},
fail(error) {
reject(error.data)
}
})
})//Promise end
}