1.登录获取用户昵称,头像
<view class="userinfo">
<image src="{
{userInfo.avatarUrl}}"></image>
<view>{
{userInfo.nickName}}</view>
</view>
<button plain bindtap="getUser">授权登陆</button>
<button plain bindtap="exitUser">退出</button>
// 获取用户信息
getUser(){
//获得用户的头像和昵称
wx.getUserProfile({
desc: '获得用户信息'
}).then((res) => {
console.log(res.userInfo.avatarUrl,res.userInfo.nickName)
this.setData({
userInfo:res.userInfo
})
// 添加到数据库用户列表中 yuyue-user
wx.cloud.database().collection('yuyue-user').add({
data:{
// 添加一个号码,由于id和openid太长,此号码可作为唯一标识
num: Date.now(),
// 添加用户昵称和头像
nickName:res.userInfo.nickName,