使用button 的open-type="getUserInfo"獲取用戶信息

官方文檔中:

wx.getUserInfo(OBJECT)

注意:此接口有調整,使用該接口將不再出現授權彈窗,請使用 <button open-type="getUserInfo"></button> 引導用戶主動進行授權操作

  1. 當用戶未授權過,調用該接口將直接報錯
  2. 當用戶授權過,可以使用該接口獲取用戶信息

所以,以後不建議直接調用:

wx.getUserInfo({
    success: function(res) {
    console(res.userInfo)
    }
})

建議改用:

wmxl:

<button wx:if="{{canIUse}}" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">授權登錄</button>
<view wx:else>請升級微信版本</view>

js:

data: {
    canIUse: wx.canIUse("button.open-type.getUserInfo")
  },
  bindGetUserInfo: function (e) {
    console.log(e)
  }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章