初学小程序 获取用户信息几个方法
1、获取用户信息的几个常用方法
(1)wx.login({})
(2)getUserInfo方法success中运用res.userInfo可以看到用户基本信息
wx.getUserInfo({
success:res=>{
userInfo = res.userInfo,
this.setData(
{
username : userInfo.nickName,
gender : userInfo.gender, //性别 0:未知、1:男、2:女
province : userInfo.province,
city : userInfo.city,
country : userInfo.country
})
}
})
(3)wx.checkSession()获取这一次会话状态
wx.checkSession({
success: (res) => {this.setData({isHide:false})},
fail:res=>{this.setData({isHide:true})}
}
(4)open-type利用button
<button class='authBtn' type='primary' open-type='getUserInfo' bindgetuserinfo='bindGetUserInfo'>授权登录</button>
其中open-type对应属性必须为getUserInfo