微信小程序授权登录界面
原先用的 wx.getUserInfo(Object object) ,现已改革
现用的 wx.getUserProfile(Object object),获取用户信息。每次请求都会弹出授权窗口,用户同意后返回 userInfo
。
1 login.js页面
const app = getApp()
//获取应用实例
Page({
data: {
userInfo: {
},
hasUserInfo: false,
canIUseGetUserProfile: false,
},
onLoad() {
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
},
goto:function(){
wx.switchTab({
url:'../pages/index/index'
})
},
getUserProfile(e) {
wx.getUserProfile({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true,
}