12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
ADADADADAD
建站问答 时间:2024-12-01 19:02:27
作者:文/会员上传
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
小程序页面自动弹出授权的方法:在index.js文件中实现。onLoad:function(options){wx.showLoading({title:'登录中'})wx.getSetting({success:res=>{console.log(res)
以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。
小程序页面自动弹出授权的方法:
在index.js文件中实现。
onLoad:function(options){wx.showLoading({
title:'登录中'
})
wx.getSetting({
success:res=>{
console.log(res)
if(res.authSetting['scope.userInfo']===true){//成功授权
//已经授权,可以直接调用getUserInfo获取头像昵称,不会弹框
wx.getUserInfo({
success:res=>{
console.log(res)
this.setUserInfoAndNext(res)
},
fail:res=>{
console.log(res)
}
})
}elseif(res.authSetting['scope.userInfo']===false){//授权弹窗被拒绝
wx.openSetting({
success:res=>{
console.log(res)
},
fail:res=>{
console.log(res)
}
})
}else{//没有弹出过授权弹窗
wx.getUserInfo({
success:res=>{
console.log(res)
this.setUserInfoAndNext(res)
},
fail:res=>{
console.log(res)
wx.openSetting({
success:res=>{
console.log(res)
},
fail:res=>{
console.log(res)
}
})
}
})
}
}
})
},
//获取个人信息成功,然后处理剩下的业务或跳转首页
setUserInfoAndNext(res){
//由于getUserInfo是网络请求,可能会在Page.onLoad之后才返回
//所以此处加入callback以防止这种情况
if(this.userInfoReadyCallback){
this.userInfoReadyCallback(res)
}
wx.hideLoading()
//跳转首页
setTimeout(()=>{
wx.reLaunch({
url:'../home/home'
})
},1000)
},
11-20
11-19
11-20
11-20
11-20
11-19
11-20
11-20
11-19
11-20
11-19
11-19
11-19
11-19
11-19
11-19