app.js页面操作wx.login
wx.login({
success: function(res) {
if (res.code) {
wx.request({
method: "POST",
url: getApp().globalData.url + '/v1/wechat/userId',
data: {
js_code: res.code
},
header: {
"Content-Type": "application/x-www-form-urlencoded",
},
success: function(res) {
wx.setStorageSync("openid", res.data.data.openid)
wx.setStorageSync("access_token", res.data.data.access_token)
wx.setStorageSync("status", res.data.data.status)
if (that.callBack){
that.callBack(res);
}
}
})
} else {
console.log('获取用户登录态失败:' + res.errMsg);
}
}
})
首页获取值
const app = getApp();
onLoad(query) {
let that = this;
//判断onLaunch是否执行完毕
if (wx.getStorageSync('access_token')) {
} else {
app.callBack = res => {
};
}
},
app.js中setStorageSync的值在页面中第一次加载取不到值,再次刷新可以取值,用这种方法解决不了,有其他方法吗?