TEST1() {
wx.showModal({
title: 'NEXT?',
content: 'DO YOU WANT TO NEXT?',
success(res) {
if (res.confirm) {
console.log("sure")
return new Promise(function (resolve, reject) {
resolve('hello');
})
} else {
console.log("no")
return new Promise(function (resolve, reject) {
resolve('hello');
})
}
}
})
console.log('first')
},
async onLoad() {
const f1 = await this.TEST1();
console.log(f1)
const f2 = await this.TEST1();
},
做了一个简单的异步回调函数,我需要第一个TEST1()运行完后再运行TEST1()
但是没有实现我需要的功能,基本还是同步先完成再到异步
这条回复仅做记录,可以这么写,但是这样写原程序逻辑可能要大改,看看大佬有什么其他答案
TEST1() {
console.log('hi')
return new Promise(function (resolve, reject) {
wx.showModal({
title: 'TEXT',
content:'hello',
success(res){
if (res.confirm) {
resolve(true);
}else{
reject(false)
}
}
})
})
},
async onLoad() {
await this.TEST1();
await this.TEST1();
},
定时器也许可以试试