//index. Js
//get application example
Const app=getApp ()
Page ({
Data: {
Motto: 'Hello World',
The userInfo: {},
HasUserInfo: false,
CanIUse: wx. CanIUse (' button. The open - type. GetUserInfo ')
},
//event handler
BindViewTap: function () {
Wx. NavigateTo ({
url: '../logs/logs'
})
},
OnLoad: function () {
If (app. GlobalData. The userInfo) {
Enclosing setData ({
The userInfo: app. GlobalData. The userInfo,
HasUserInfo: true
})
} else if (this. Data. CanIUse) {
//since getUserInfo is network request, may be on the Page. The onl oad before returning to
//so I join the callback to prevent this kind of circumstance
App. UserInfoReadyCallback=res=& gt; {
Enclosing setData ({
The userInfo: res. The userInfo,
HasUserInfo: true
})
}
} else {
//in the absence of open - type=getUserInfo version compatibility processing
Wx. GetUserInfo ({
Success: res=& gt; {
App. GlobalData. The userInfo=res. The userInfo
Enclosing setData ({
The userInfo: res. The userInfo,
HasUserInfo: true
})
}
})
}
},
GetUserInfo: function (e) {
The console. The log (e)
App. GlobalData. The userInfo=e.d etail. The userInfo
Enclosing setData ({
The userInfo: e.d etail. The userInfo,
HasUserInfo: true
})
}
})
CodePudding user response:
Mark, to ask,CodePudding user response:
App. GlobalData. The userInfo is not have this