(七)获取用户信息

下面我们介绍一种官方推荐的获取用户信息的方法

  • wxml
<view>当前用户名:{{name}}</view>
<view>
当前用户头像:
<image src="{{path}}" style="width:200rpx;height:200rpx"></image>
</view>


<button  open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">授权登录</button>
  • wxjs
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)
      }
    })
  },
})

 

posted @ 2019-02-22 16:25  流年中渲染了微笑  阅读(380)  评论(0编辑  收藏  举报