使用uniapp开发小程序获取用户信息按钮需要点击两次才能获得到用户信息?
用uniapp开发小程序,开发者工具本地测试没有问题,但是真机测试的时候获取用户信息那里不知道为何要点两次才能成功,第一次会提示错误 getUserProfile:fail can only be invoked by user TAP gesture
第二次才会成功,底下是我的代码
<button v-if="but" class='bottom' type='primary' @click="goLogin">
获取用户信息
</button>
getUserProfile() {
// 判断缓存中是否有用户数据,没有则获取
uni.getUserProfile({
desc: '獲取您的昵稱、頭像、地區及性別',
success: infoRes => {
console.log('登陆成功', infoRes)
if (infoRes.errMsg === 'getUserProfile:ok') {
uni.showToast({
title: '授權成功',
icon: 'success'
});
} else {
uni.showToast({
title: '授權失敗',
icon: 'error'
});
}
},
fail: err => {
console.log('userInfo-err', JSON.stringify(err));
}
});
},
我尝试过使用 <button v-if="but" class='bottom' type='primary' open-type="getUserProfile" bindtap="getUserProfile" >
获取用户信息
</button>
但是又会出现另外一个错误 "pages/login/login" does not have a method "getUserProfile" to handle event "tap"