1
<view class='my_head'> <!-- <image class='my_head_img' src='/image/head.png'></image> --> <image class='my_head_img' src='{{user_img}}'></image> </view> <view class='my_head_name'> {{user_name}} </view>复制代码
2
Page({
/** * 页面的初始数据 */ data: { canIUse: wx.canIUse('button.open-type.getUserInfo'), 'user_name': "", 'user_img': "", },
/** * 生命周期函数--监听页面加载 */ onLoad: function(options) { var that = this; // 查看是否授权 wx.getSetting({ success: function(res) { if (res.authSetting['scope.userInfo']) { // 已经授权,可以直接调用 getUserInfo 获取头像昵称 wx.getUserInfo({ success: function(res) { // console.log(res.userInfo) that.info(res.userInfo) } }) } } }) },
// 处理获取的头像信息 info: function (res) { console.log(res) this.setData({ user_name: res.nickName, user_img: res.avatarUrl, }) },})复制代码