效果
wxml页面
给button绑定冒泡事件,也就是我们说的点击事件
<button bindtap="getUserProfile" >授权登录</button>
js页面
这里wx.getUserProfile方法可以从底部弹框提示用户授权,success是用户确认授权回调方法,
可以console.log(result)查看以下数据,可以在userInfo中获取用户的一些基本信息,例如头像,昵称。通过wx.login()获取微信平台提供给我们的code(5分钟内有效,每次请求code都不一样),有了code我们就可以通过wx.request()向后端发起请求了
getUserProfile(e){
let that = this;
wx.getUserProfile({
desc: '展示用户信息',
success: (result) => {
// 接收名称和头像
let nickName = result.userInfo.nickName;
let avatarUrl = result.userInfo.avatarUrl;
wx