获取微信用户的基本信息
函数wx.getUserInfo(),其返回的结果包含又用户的基本信息
js文件代码:
Page({
data:{
userInfo:[], //保存获取得到的用户信息
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var self = this //代表的是当前的js文件的整个page
wx.getUserInfo({
success: res => {
console.log("得到的结果:")
console.log(res)
self.setData({
userInfo: res.userInfo
})
console.log("userInfo:")
console.log(self.data.userInfo)
}
})
}
})
wxml文件代码:
<view class="contain">
<view class="img">
//用户touxiang
<image src="{{userInfo.avatarUrl}}" class="headIcon"></image>
</view>
//用户名称
<view class="nickName">{{userInfo.nickName}}</view>
</view>
页面显示:

1万+

被折叠的 条评论
为什么被折叠?



