uni-app uni.request同步操作

uni-app uni.request同步操作逻辑
onload 中调用this.doTest()方法,会先执行 uni.request中打印的console.log(res),
再执行console.log(‘后打印’)
onLoad() {
this.doTest();
},
methods: {
async doTest(){
await this.getTest();
console.log(‘后打印’); //后打印
},
getTest(){
return new Promise((resolve,reject)=>{
uni.request({
url: ‘https://…’,
method: ‘POST’,
data: {},
success: res => {
console.log(res); //先打印
resolve(‘success’);
},
fail: (err) => {
console.log(err);
reject(‘error’);
}
})
})
}
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-11
  • 2021-08-14
  • 2021-09-19
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
猜你喜欢
  • 2021-12-22
  • 2022-12-23
  • 2021-09-14
  • 2021-05-04
  • 2021-08-11
  • 2022-02-06
  • 2022-12-23
相关资源
相似解决方案