WeChat Mini Programs"s wx.request is an asynchronous request. Perform background interaction in app.js onLaunch to obtain openid
APP({
onLaunch:function(){
//
wx.login({
success:res => {
var code = res.code
if(code){
wx.request({
url:xxx,
method:xxx,
success: res =>{
var that = this;
console.log("app.js---onLaunch")
that.globalData.openid = res.data.openid
}
})
}
}
})
}
})
want to get openid in onReady phase in index.js
const app = getApp()
......
onReady:function(){
console.log("index.js--onReady")
console.log(app.globalData.openid)
}
the result is as follows
my goal is to get the openid on the index.js page and then do the this.setData ({})
assignment, but there is no value at this time because of asynchronism. I have tried several asynchronous methods, promise and cb. I just came into contact with javascript, but the train of thought is not very clear. is there an asynchronous callback?