wxml
{userinfo.avatarUrl}}"> {{userinfo.nickName}}
js
data: {//用户基本信息(头像、昵称)userinfo: {avatarUrl:'../../images/ckbg1.png',nickName:'未授权'},//是否已经获取用户信息hasUserInfo: false,//是否可以调用获取信息得函数canIUseGetUserProfile: false,},//第一次获取用户信息
getUserProfile : function(e){wx.getUserProfile({desc: '获取您的微信个人信息',success:(res)=>{this.setData({userinfo:res.userInfo,hasUserInfo:true})wx.setStorageSync('userinfo', res.userInfo)},fail:function(e){wx.showToast({title: '你选择了取消',icon: "none",duration: 1500,mask: true})}})
},onLoad: function(n) {this.setData({canIUseGetUserProfile : true})},
onShow: function() {//获取用户的本地缓存数据,userinfo信息是在用户授权登录时保存的var n = wx.getStorageSync("userinfo");//当本地缓存的用户名称不为""或者null时,设置userinfo信息if(n.nickName != '' && n.nickName != null){this.setData({userinfo: n,hasUserInfo:true,canIUseGetUserProfile:true})// 通过wx.login获取登录凭证(code),然后通过code去获取我们用户的openidwx.login({success:(res)=>{console.log(res);},})}//清空缓存信息,测试使用// wx.removeStorage({// key: 'userinfo',// });
},
.banner {border-radius: 10rpx;border: none;box-sizing: content-box;padding: 20rpx 0;width: 90%;height: 370rpx;margin: 20rpx auto;background:linear-gradient(109.6deg, rgb(204, 228, 247) 11.2%, rgb(237, 246, 250) 100.2%);/* background-image:image("../../images/cloudbg.jpg"); */text-align: center;
}.topContainer {width: 100%;height: 260rpx;background-size: 100%;border-radius: 9px;
}
.userinfo-nickname {color:black;
}
.userLogin{width: 50%;box-sizing: none;font-size: medium;
}
.userinfo-avatar {width: 150rpx;height: 150rpx;margin-bottom: 10rpx;border-radius: 50%;
}
上一篇:你不知道的goland技巧
下一篇:分销商城小程序系统怎么选择?