下面咱们介绍一种官方推荐的获取用户信息的方法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) } }) }, })