小程序新用户注册获取获取不到openId,求指点一下,是什么原因呢?
注册页面
onLoad: function (options) {
this.memberTypesFn()
console.log(options.openId)
this.setData({
['msg.openId']:wx.getStorageSync('openId')
})
},
这个console打印出来的是undefined,
//登录页面
weixinLogin: function () {
//微信登录
let _this = this;
wx.login({
success(res) {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
console.log(res.code)
可以打印出来res.code, openId是空
_this.httpClient.get(_this.api.loginUrl, {
code: res.code
})
.then(res1 => {
console.log(res1)
if (res1.data.code == '0') {
wx.setStorageSync('user', res1.data.data.user)
console.log(1111)
//登录成功
} else if (res1.data.code == '102') {
//没有绑定
console.log(2222)
_this.globalData.openid = res1.data.data.openId;
let openId = res1.data.data.openId;
wx.clearStorageSync()
wx.setStorageSync('openId', openId)
} else {
console.log(3333)
_this.msg.showToast(res1.data.msg, 'none');
console.log(res1.data.msg)
}
})
.catch(res => {
app.msg.showToast('请求失败', 'error')
})
}
})
},
走完之后打印一直走的是console.log(3333),望指点一下什么原因