继上一篇博客讲到的uniapp微信授权登录补充
今天才发现的问题,wx.authorize()
接口的success(){}
回调函数在电脑微信测试端才会执行,在手机小程序测试不会执行,点击同意后还是授权失败,这就导致电脑端小程序测试是通过的,手机端测试就通不过!还是我的小伙伴帮忙解决的@曹建宇很棒!
解决办法:
我们就不用success(){}
回调函数,用complete(){}
接口调用结束时的回调函数
调用uni.getSetting(){}
接口,返回用户操作的结果true或false来执行后面需要的操作
上代码:
<button @getuserinfo="getUserInfo" bind open-type="getUserInfo">获取用户信息</button>
method:{
getUserInfo(){
uni.authorize({
scope:"scope.userInfo",
complete(e){
uni.getSetting({
success (res) {
console.log(res)
if(res.authSetting["scope.userInfo"]){
uni.showLoading({
title: '登录中...'
});
}else{
uni.showToast({
"title":"登录失败,请重新授权",
"icon":"none"
})
}
}
})
}
})
}
}