1. 程式人生 > >微信小程式之使用者資訊授權 wx.getUserInfo

微信小程式之使用者資訊授權 wx.getUserInfo

使用者授權

<button open-type="getUserInfo" bindgetuserinfo='getUser'>授權使用者資訊</button>
getUser(e) {
    console.log(e);
    wx.getUserInfo({
        success: (res) => {
            console.log(res)
            this.setData({
                userInfo: res.userInfo
            });
        }
    })
}
  • 點選上面 button 後彈出授權視窗;
  • 如果使用者同意授權,將獲取到使用者資訊,再次點選button後不會彈窗。
  • 如果使用者拒絕授權,不會獲取到使用者資訊,再次點選按鈕,會再次彈出授權視窗。