Home > Mobile >  Small program examples using WeChat authorization login, after other pages how to get the login user
Small program examples using WeChat authorization login, after other pages how to get the login user

Time:09-20

The following code is a small program default landing, but the other how to judge whether the user login page? Not every page to write such a right,

 
//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
  • Related