I wrote the login / acquisition user information in app.js. After success, I assigned the content to the onLoad of globalData.xxxxx,Page and then assigned the globalData.xxxxx to data.xxxxx. I found that the assignment was not so bad. Many materials say that the problem of onLoad,onLaunch,request asynchronous request leads to how to solve it.
app.js
app({
globalData: {
xxxxx: null
},
onLaunch: function () {
var that = this;
wx.login({
success: function (res) {
var code = res.code;
if (code) {
wx.getUserInfo({
success: function (res) {
wx.request({
.....
},
success: function (data) {
that.globalData.xxxxx = data.data.xxxxx
},
fail: function () {
console.log("")
}
})
},
fail: function () {
console.log(",")
}
})
} else {
console.log("" + res.errMsg)
}
},
fail: function () {
console.log("")
}
})
}
})
index.js
var app = getApp();
Page({
data: {
xxxxx:null
},
onLoad: function (options) {
this.setData({
xxxxx: app.globalData.xxxxx
});
}
})