wx.getSetting({
success: res => {
if (res.authSetting["scope.userInfo"]) {
wx.getUserInfo({
success: res => {
this.globalData.userInfo = res.userInfo
}
})
} else (
wx.authorize({
scope: "scope.userInfo",
success() {
wx.getUserInfo({
success:res=>{
this.globalData.userInfo =res.userInfo
}
})
}
})
)
}
})
console.log("wa")
this.setData({
userInfo: app.globalData.userInfo,
hasUserInfo: true
})
I console for a while and find that onload will have "wa"," when the authorization application pops up in the debug interface. But the life cycle onlunch of Mini Program seen on the Internet is higher than onload. According to reason, I changed the global userInfo variable after the authorization was successful. When loading the page, the local variable of the page can also successfully obtain the global global variable, but it is still null
in the console.use this.userInfoReadyCallback in the official example to solve the problem, but this.userInfoReadyCallback does not seem to be found in the official API, and the loading order of the page is still in doubt. Ask God to explain ~