微信小程序開發時,Console 提示:獲取 wx.getUserInfo 接口后續將不再出現授權彈窗,請注意升級

錯誤原因:
直接調用這個方法依舊可以獲取用戶信息, 但是如果你之前沒有點擊過那個授權的小彈出框,這個方法就直接報錯了,需要你直接去引導用戶去授權。
解決方法:
微信更新api后,wx.getUserInfo在開發和體驗版本都不能彈出授權窗口。使用該接口將不再出現授權彈窗,請使用 <button open-type="getUserInfo"></button> 引導用戶主動進行授權操作。
wx.getUserInfo({
withCredentials: true,
success: function (res) {
//此處為獲取微信信息后的業務方法
},
fail: function () {
//獲取用戶信息失敗后。請跳轉授權頁面
wx.showModal({
title: '警告',
content: '尚未進行授權,請點擊確定跳轉到授權頁面進行授權。',
success: function (res) {
if (res.confirm) {
console.log('用戶點擊確定')
wx.navigateTo({
url: '../tologin/tologin',
})
}
}
})
}
})
調用此方法失敗后,跳轉授權頁面
<button open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">授權登錄</button>
Js中
bindGetUserInfo: function(e){
var that = this;
//此處授權得到userInfo
console.log(e.detail.userInfo);
//接下來寫業務代碼
//最后,記得返回剛才的頁面
wx.navigateBack({
delta: 1
})
}
!!!!!!!!!!!!!!!!!!!!!!!!!
另外:開發工具需要這么設置,否者用接口的時候會報錯

報錯圖片:

