功能比较简单,这里直接上代码: .js
onGetUserInfo: function(e) { if (!this.data.logged && e.detail.userInfo) { console.log('==允许',this.data.logged) this.setData({ logged: true, avatarUrl: e.detail.userInfo.avatarUrl, userInfo: e.detail.userInfo }) console.log('==头像为:',this.data.avatarUrl) console.log('==昵称为:',this.data.userInfo) }else{ console.log('==拒绝') wx.showToast({ title: '需要获取权限才可以做评论', icon:"none" }) } },.wxml
<button open-type="getUserInfo" bindgetuserinfo="onGetUserInfo" class="userinfo-avatar" style="background-image: url({{avatarUrl}})" size="default" ></button>.wxss
.userinfo-avatar { width: 100rpx; height: 100rpx; margin: 20rpx; border-radius: 50%; background-size: cover; background-color: white; } .userinfo-avatar[size] { width: 100rpx; } .userinfo-avatar:after { border: none; }