小程序受权登陆
<button class="l_btn" open-type="getUserInfo" lang="zh_CN" @getuserinfo="bindGetUserInfo" @click="getUserInfoClick">微信登陆 </button>
小程序
getUserInfoClick() {}, //不要删除 bindGetUserInfo: function (e) { var that = this; var sessionId = wx.getStorageSync("sessionId"); if (e.mp.detail.userInfo) { var userInfo = e.mp.detail.userInfo; userInfo.encryptedData = e.mp.detail.encryptedData; userInfo.iv = e.mp.detail.iv; wx.setStorageSync("userInfo", userInfo); wx.switchTab({ url: "/pages/home/main" }); } else { wx.showModal({ content: '请容许使用微信登陆', confirmText: "确认", cancelText: "取消", success: function (res) { //点击“确认”时打开设置页面 if (res.confirm) { wx.openSetting({ success: (data) => { if (data.authSetting["scope.userInfo"] == true){ wx.getUserInfo({ // withCredentials: false, lang:"zh_CN", success: function (datares) { var userInfo = datares.userInfo; userInfo.encryptedData = datares.encryptedData; userInfo.iv = datares.iv; wx.setStorageSync("userInfo", userInfo); wx.switchTab({ url: "/pages/home/main" }); }}) } } }) } else { console.log('用户点击取消') } } }); } },