button

  1. //这里的open-type基本没有用了,它的功能已经可以在点击事件中调用uni.getUserProfile()函数代替
  2. <button v-else class="btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" lang="zh_CN">
  3. <image src="../../static/login/mobile.png" mode=""></image>
  4. <text>获取手机号</text>
  5. </button>
  6. // 获取手机号
  7. async getPhoneNumber(e) {
  8. this.detail = e.detail
  9. this.getUser()
  10. },
  11. async getUser() {
  12. // 调用接口,并传入信息。
  13. let res = await login({
  14. companyId: this.companyId,
  15. inviterId: this.inviterId,
  16. avatar: this.userInfo.avatarUrl,
  17. nickname: this.userInfo.nickName,
  18. sex: this.userInfo.gender,
  19. encryptedData: this.detail.encryptedData,
  20. iv: this.detail.iv,
  21. wxCode: this.code,
  22. type: 0
  23. })
  24. // 将返回的token保存
  25. uni.setStorageSync('token', res.token)
  26. const userInfo = await getUserInfo()
  27. uni.setStorageSync('userInfo', userInfo)
  28. this.nagateUrl()
  29. },

open-type属性,引导用户进行授权

微信更新了新的获取用户信息的方法,之前的getUserInfo方法获取不到用户的头像等信息,继续使用也会得到 灰色的头像 不是真正的用户头像
之前的获uniapp 中获取用户信息方法:

  1. <button open-type="getUserInfo" @getuserinfo="getUserInfo">立即登录</button>

新的 获取用户信息方法:

  1. //不要使用 open-type 就简单的一个@click 事件
  2. //方法:
  3. <button @click="getUserInfo">请登录</button>
  4. getUserInfo(){
  5. console.log("aaaa")
  6. uni.getUserProfile({
  7. desc:'Wexin', // 这个参数是必须的
  8. success:res=>{
  9. console.log("用户信息",res.rawData)
  10. }
  11. })
  12. }