1、直接使用open-data
组件
- 无需用户弹窗确认
<open-data type="groupName" open-gid="xxxxxx"></open-data>
<open-data type="userAvatarUrl"></open-data>
<open-data type="userGender" lang="zh_CN"></open-data>
2、wx.getUserProfile
- 每次调用此接口均会弹窗让用户授权,因此要注意保存用户信息
- 页面产生点击事件(例如 button 上 bindtap 的回调中)后才可调用
//.wxml
<button bindtap="getUserProfile"> 获取头像昵称 </button>
//.js
getUserProfile(e) {
wx.getUserProfile({
desc: '展示用户信息', /
success: (res) => {
console.log(res)
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
}