下面咱們介紹一種官方推薦的獲取用戶信息的方法ide
<view>當前用戶名:{{name}}</view> <view> 當前用戶頭像: <image src="{{path}}" style="width:200rpx;height:200rpx"></image> </view> <button open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">受權登陸</button>
Page({ data: { name: "", path: "/static/default.png" }, bindGetUserInfo: function () { var that = this; wx.getUserInfo({ success: function (res) { that.setData({ name: res.userInfo.nickName, path: res.userInfo.avatarUrl, }) }, fail: function (res) { console.log('fail', res) } }) }, })