700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 微信小程序获取用户信息-头像 昵称......

微信小程序获取用户信息-头像 昵称......

时间:2021-03-06 21:12:48

相关推荐

微信小程序获取用户信息-头像 昵称......

微信小程序获取用户信息-头像、昵称等,并出现弹窗提示授权

目录

微信小程序获取用户信息-头像、昵称等,并出现弹窗提示授权1.wx.getUserProfile文档2.代码演示3.演示过程(图示)

1.wx.getUserProfile文档

官网文档:(链接:wx.getUserProfile)

参数如下

回调函数

2.代码演示

wxml中:(class、src自己定义)

<image wx:if='{{userInfo.avatarUrl}}' class="hpicture" src="{{userInfo.avatarUrl}}"></image><button wx:else bindtap="getUserProfile" >获取用户信息</button>

js中:

data: {userInfo:{//用户的基本信息},user:{username:'章',school:''}},//获取用户信息的回调getUserProfile(e) {wx.getUserProfile({desc: '资料', success: (res) => {//修改userInfo的状态数据this.setData({userInfo: res.userInfo,})},fail:(err) =>{console.log(err);}})},

3.演示过程(图示)

我的代码效果如下:

图1

点击头像登录

图2

点击拒绝后 同图1

点击允许:(显示微信头像和昵称)

图3

在AppData中查看userInfo的数据

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。