关于Promise的知识和async及其await的使用
new Promise(function(resove, reject){
uni.request({
url: getApp().globalData.Interfaceurl + 'grantWxInfo',
method: "post",
header: {
"content-type": "application/x-www-form-urlencoded;charset=UTF-8"
},
data: {
userId: getApp().globalData.userId,
rawData: res.rawData,
signature: res.signature,
encryptedData: res.encryptedData,
iv: res.iv
},
success(rest) {
resove(rest)
// console.log(rest)
},
fail(errs) {
// reject(errs)
}
})
}).then(
res=>console.log(res,2222),
err=>console.log(err,3333)
)
async和await的使用
async getPhoneNumber(e) {
// console.log(e)
await new Promise(function(resove,reject){
uni.request({
url: getApp().globalData.Interfaceurl + 'grantWxMobile',
method: "post",
header: {
"content-type": "application/x-www-form-urlencoded;charset=UTF-8"
},
data: {
userId: getApp().globalData.userId,
encryptedData: e.detail.encryptedData,
iv: e.detail.iv,
},
success(res) {
resove(res)
console.log(res)
},
error(err){
console.log(err)
}
})
})