test:async function(){
var that=this;
console.log('0');
const p=await new Promise(function(resolve,reject){
that.a();
resolve();
})
console.log('2');
},
a:function(){
wx.showModal({
showCancel: false,
confirmText:'确定',
content:'1',
title:'提示',
success:function(res){
if(res.confirm){
console.log('1');
}
}
})
如何在函数里调用另一个函数?目的是按顺序执行输出012,我试过直接将wx.showModal放到Promise里是可以按顺序输出的。
test:async function(){ var that=this; console.log('0'); const p=await this.a() console.log('2'); }, a:async function(){ let res = await wx.showModal({ showCancel: false, confirmText:'确定', content:'1', title:'提示', }) if(res.confirm){ console.log('1'); } }
在a函数里面接收resolve,在modal success中执行