uniapp小程序微信授权获取头像昵称

最近修改小程序发现线上版的小程序通过uni.getUserProfile获取到的头像为默认灰色头像,昵称为微信用户,体验版能够正常获取到头像昵称,详参考链接小程序用户头像昵称获取规则调整公告

解决方法参考链接获取头像昵称

<!-- 头像获取 -->
<button type="primary" open-type="chooseAvatar" @chooseavatar="onChooseAvatar" plain="true"
      style="width: 150rpx;height: 150rpx;border-radius: 20rpx;margin-bottom: 100rpx;margin-top: 20vw;border: none;position: relative;">
      <image :src="avatar" mode="aspectFill" style="width: 150rpx;height: 150rpx;border-radius: 20rpx;" v-if="avatar">
      </image>
      <image src="../../static/home/noavatar.jpg" mode="aspectFill"
        style="width: 150rpx;height: 150rpx;border-radius: 20rpx;" v-else></image>
      <view class="tips">点击授权头像</view>
    </button>

<!-- 昵称获取 -->
<input type="nickname" style="font-size: 28rpx;color: #666666;flex: 1;" placeholder="请输入昵称" v-model="nickname" @blur="getNickname"/>
// 获取头像
onChooseAvatar(e){
   const { avatarUrl } = e.detail   // 此返回的路径为临时路径,需转换为永久路径保存使用
   this.avatar = avatarUrl
 },
// 获取昵称
getNickname(e){
   this.nickname = e.detail.value
 },

在需要授权才能使用的操作或跳转中先验证是否已授权,若未授权跳转授权页面,授权成功提交后返回

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值