小程序登录
index.wxml
<button open-type="getUserInfo" bindgetuserinfo="auth" wx:if="{{showAuth}}">授权登录<button>
<block wx:else>
<image class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}
<block>
index.js
Page{
data(){
userInfo:{},
showAuth:true
},
auth:function(e){
this.setData({
userInfo:e.detail.userInfo,
showAuth:false
});
},
onLoad:function(){
var that=this;
if(res.authSetting['scope.userInfo']){
wx.getUserInfo({
that.setData({
userInfo:res.userInfo,
showAuth:false
})
}
}
}
服务端获取openid
getUserInfo:function(e){
}