小程序开发坑之---------微信api更新,不会主动弹出授权框,getUserInfo使用报错...

解决方法:自写一个展示框,判断是否授权,未授权的情况下弹出授权框,授权后不会弹出

代码:

弹出框页面view:
 
<view wx:if="{{!canIUse&&showShouquan}}" style='height:100vh;width:100vw;opacity:.5;position:absolute;top:0'></view>
<view wx:if="{{!canIUse&&showShouquan}}" style='color:#333333;position:absolute;top:340rpx;width:70vw;left:9vw;padding:6vw'>
<view style='font-size:42rpx'>微信授权</view>
<view style='font-size:30rpx;font-weight:bold;text-align:center;padding:20rpx;border-bottom:1px solid #e9e9e9'>....网络科技申请获取以下权限:</view>
<view style='font-size:26rpx;text-align:center;margin:30rpx 30rpx 70rpx 30rpx'><text>获得你的公开信息(昵称、头像等)</text></view>
<view style='font-size:28rpx;float:right;margin-top:10rpx'>
<text wx:if="{{!canIUse&&showShouquan}}" bindtap='hidthis' style='color:#999999;margin-left:60rpx;height:60rpx;line-height:60rpx;font-size:30rpx;border:none;position:absolute;top:300rpx;left:300rpx'>拒绝</text>
<button wx:if="{{!canIUse}}" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo" style='color:#31B531;margin-left:60rpx;height:60rpx;line-height:60rpx;font-size:30rpx;border:none;position:absolute;top:300rpx;left:400rpx'>允许</button>
</view>
<!-- userInfo:getApp().globalData.userInfo -->
</view>

js:

data: {
  canIUse: wx.canIUse('button.open-type.getUserInfo'),
  showShouquan:true
},
onLoad: function (options) {
  // 查看是否授权
  wx.getSetting({
    success: function (res) {
      console.log(res.authSetting['scope.userInfo'])
      if (res.authSetting['scope.userInfo']) {
      // 已经授权,可以直接调用 getUserInfo 获取头像昵称
      wx.getUserInfo({
        success: function (res) {
        console.log(res)
        getApp().globalData.userInfo = res.userInfo   //将授权信息传递给全局变量
      }
    })
    }
  }
  })
},
bindGetUserInfo: function (e) {
  getApp().globalData.userInfo = e.detail.userInfo     //将授权信息传递给全局变量
  console.log(getApp().globalData.userInfo)
},
 
 

转载于:https://www.cnblogs.com/DesignerFly/p/9039367.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值