厦门营销网站制作,成都手工活外发加工网,北京网站建设排行,net mvc 仿wordpress配置旧版本基础库2.12.3 实现效果 点击登录按钮即可直接登录#xff0c;获取用户昵称和头像 点击获取头像昵称按钮则需要授权#xff0c;才能成功登录 代码实现
my.xml
!-- 登录页面,调试基础库为2.20.2库 --
view classmyloginblock w…配置旧版本基础库2.12.3 实现效果 点击登录按钮即可直接登录获取用户昵称和头像 点击获取头像昵称按钮则需要授权才能成功登录 代码实现
my.xml
!-- 登录页面,调试基础库为2.20.2库 --
view classmyloginblock wx:if{{isLogin}}image src{{src}}/imagetext{{nickName}}/text/blockbutton wx:else open-typegetUserInfo bindgetuserinfogetMyInfo未登录点此登录/button
/viewview classcontainerview classuserinfoblock wx:if{{!hasUserInfo}}button wx:if{{canIUseGetUserProfile}} bindtapgetUserProfile 获取头像昵称 /buttonbutton wx:else open-typegetUserInfo bindgetuserinfogetUserProfile 获取头像昵称 /button/blockblock wx:elseimage bindtapbindViewTap classuserinfo-avatar src{{userInfo.avatarUrl}} modecover/imagetext classuserinfo-nickname{{userInfo.nickName}}/text/block/view
/viewmy.js
Page({/*** 页面的初始数据*/data: {nickName:未登录},//获取个人信息调试基础库为2.12.3getMyInfo:function(e){let that this;wx.login({success (res) {if (res.code) {let info e.detail.userInfo} else {console.log(登录失败 res.errMsg)}that.setData({src: e.detail.userInfo.avatarUrl,nickName: e.detail.userInfo.nickName,isLogin: true})}})},getUserProfile(e) {// 推荐使用wx.getUserProfile获取用户信息开发者每次通过该接口获取用户个人信息均需用户确认// 开发者妥善保管用户快速填写的头像昵称避免重复弹窗wx.getUserProfile({desc: 用于完善会员资料, // 声明获取用户个人信息后的用途后续会展示在弹窗中请谨慎填写success: (res) {this.setData({userInfo: res.userInfo,hasUserInfo: true})}})}
})控制台打印微信登录用户基本信息