
getuserInfo 官方更改后 又生起一波的吐槽 啊哈哈。 这几天 赶着交项目 没啥时间今天传一波,我就直接上图了。
判断是否有缓存。 没有直接跳转 登录页 (index.js) onLoad里
wx.getStorage({ //如果没有缓存内容直接 跳转 登录页授权
key: 'loginInformation',
success: function (res) {
console.log(res)
console.log("缓存")
if (res.data == undefined) {
wx.reLaunch({
url: '../login/login',
})
}
},
fail: function (res) {
console.log(res)
//if (res.errMsg == "getStorage:fail data not found") {
wx.reLaunch({
url: '../login/login',
})
//}
},
})

login页面 wxml: ( <button bindgetuserinfo="getUserInfo" open-type='getUserInfo'>点击授权</button>)
getUserInfo: function (e) {
app.onLaunch()
app.globalData.userInfo = e.detail.userInfo
wx.setStorage({
key: "loginInformation",
data: e.detail.userInfo
})
console.log("首页")
wx.switchTab({
url: '../index/index',
})
}

