button
//这里的open-type基本没有用了,它的功能已经可以在点击事件中调用uni.getUserProfile()函数代替
<button v-else class="btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" lang="zh_CN">
<image src="../../static/login/mobile.png" mode=""></image>
<text>获取手机号</text>
</button>
// 获取手机号
async getPhoneNumber(e) {
this.detail = e.detail
this.getUser()
},
async getUser() {
// 调用接口,并传入信息。
let res = await login({
companyId: this.companyId,
inviterId: this.inviterId,
avatar: this.userInfo.avatarUrl,
nickname: this.userInfo.nickName,
sex: this.userInfo.gender,
encryptedData: this.detail.encryptedData,
iv: this.detail.iv,
wxCode: this.code,
type: 0
})
// 将返回的token保存
uni.setStorageSync('token', res.token)
const userInfo = await getUserInfo()
uni.setStorageSync('userInfo', userInfo)
this.nagateUrl()
},
open-type属性,引导用户进行授权
微信更新了新的获取用户信息的方法,之前的getUserInfo方法获取不到用户的头像等信息,继续使用也会得到 灰色的头像 不是真正的用户头像
之前的获uniapp 中获取用户信息方法:
<button open-type="getUserInfo" @getuserinfo="getUserInfo">立即登录</button>
新的 获取用户信息方法:
//不要使用 open-type 就简单的一个@click 事件
//方法:
<button @click="getUserInfo">请登录</button>
getUserInfo(){
console.log("aaaa")
uni.getUserProfile({
desc:'Wexin', // 这个参数是必须的
success:res=>{
console.log("用户信息",res.rawData)
}
})
}