uni await的应用
方法前面加上async 在异步方法哪里加上await
async onChange() {
// 加上 await
const mes = await this.getPrice()
console.log(mes)
}
方法返回一个promise对象 resolve写在success reject则在fail
getPrice(){
return new Promise((resolve,reject)=>{
uni.request({
url: url,
data: data,
method: method,
success: (res) => {
resolve(res)
},
fail: (res) => {
reject()
}
})
})
}