封装的代码 拿别人的用
返回
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',
},
success(request) {
if (request.errMsg === 'request:ok') {
resolve(request.data)
} else {
reject(request.data)
}
},
fail(error) {
reject(error.data)
}
})
})//Promise end
}
const post = (url, options) => {
return request(url, { method: 'POST', data: options })
}
const request =async (url, options) => { return await new Promise((resolve, reject) => {
return Pro.then(value => value) 即使实例 then 也不好使