關於小程序序授權登錄的個人理解
官網地址:小程序登錄與後端交互和小程序授權
你需要使用button按鈕去設置一個點擊授權的按鈕
<view>
<button open-type="getUserInfo" bindgetuserinfo="handleUserInfoClick">點擊登錄<button>
</view>
// open-type 必須是getUserInfo,事件必須是bindgetuserinfo這個事件
handleUserInfoClick: function (e) {
// console.log(e)
var that = this;
wx.getSetting({
success(res) {
// console.log(res)
if (res.authSetting['scope.userInfo']) {
wx.getUserInfo({
success: (res) => {
console.log(that)
console.log(res.userInfo)
that.setData({
nickName: res.userInfo.nickName,
avatarUrl: res.userInfo.avatarUrl
})
}
})
}
}
})
},
//js的代碼當我點擊的時候就會彈出讓微信授權的彈出框,然後點擊允許就會獲取個人信息。
這個方法是我自己寫的,它需要每次去點擊獲取個人信息,我們新建項目的時候那個不是,那個是獲取一次,就會自動獲取,這個只不過是讓像我這樣的小白知道,怎麼樣才能獲取到授權。