【微信小程序】2022最新用户信息授权方式

先看一波调整公告

 用户信息授权方式变更为”头像昵称填写“

 最新授权方式 可自定义 也可使用微信信息

代码:

<button class="avatar-wrapper" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
  <image class="avatar" src="{{avatarUrl}}"></image>
</button> 
<input type="nickname" class="weui-input" placeholder="请输入昵称"/>

根据调整修改交互方式UI设计效果如下

 点击头像进行授权微信头像或自定义上传图片

 

提示bind:chooseavatar返回的图片数据是临时图片 可通过wx.uploadFile 上传至自己的服务器 代码如下

 // 头像
  onChooseAvatar(e: any){
    const that = this
    wx.showLoading({title:'上传中...'})
    wx.uploadFile({
      url: config.configUrl + '/mini/upLoadFile',
      filePath: e.detail.avatarUrl,
      name: 'file',
      header: {},
      success (res){
        wx.hideLoading()
        console.log(res)
        if(res.statusCode == 200) {
          let obj = JSON.parse(res.data)
          that.setData({
            avatarUrl: obj.data
          })
        }
      }
    })
  },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值