wxml:
<view class="Box">
<image class="avatar" src="{{userInfo.avatarUrl}}"></image>
<text>{{userInfo.nickName}}</text>
<button size="mini" type="primary" plain="true" loading="true" open-type="getUserInfo" bindgetuserinfo="getUserInfo">获取用户信息</button>
</view>
open-type="getUserInfo":getUserInfo获取用户信息
bindgetuserinfo="getUserInfo":用户点击该按钮时会返回获取到的用户信息,回调的detail数据与wx.getUserInfo返回的一致
wxss:
.Box{
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
}
.avatar{
width: 200rpx;
height: 200rpx;
margin-top: 250rpx;
}
.Box text{
margin-top: 250rpx;
}
.Box button{
margin-top: 250rpx;
}
js:
data: {
userInfo: null,
},
/* 获取用户信息 */
getUserInfo(res) {
console.log(res);
this.setData({
userInfo: res.detail.userInfo
})
},