微信小程序獲取用戶信息


微信小程序使用按鈕獲取用戶信息

<button class="submitBtn" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">微信登錄</button>

open-type="getUserInfo"  獲取用戶信息,可以從bindgetuserinfo回調中獲取到用戶信息;

bindgetuserinfo="bindGetUserInfo" 用戶點擊該按鈕時,會返回獲取到的用戶信息,想要觸發bindgetuserinfo事件要先給button標簽添加open-type類型;

  bindGetUserInfo(e){
    const that=this;
    // 查看是否授權
    wx.getSetting({
      success(res) { 
        if (res.authSetting['scope.userInfo']) {
          // 已經授權,可以直接調用 getUserInfo 獲取頭像昵稱
          wx.getUserInfo({
            success(res) {
               console.log(res)
            }
          })
        }else{
          console.log("拒絕")
        }
      }
    })
  },

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM