微信小程序 获取头像和昵称

2023-12-18  本文已影响0人  码农界四爷__King

获取头像

xml
  <button class="avatar-wrapper" open-type="chooseAvatar" bindchooseavatar="onChooseAvatar">
    <image class="avatar" src="{{userInfo.avatar || ''}}"></image>
  </button>
js
  // 选择头像
  onChooseAvatar(e) {
    console.log('选择头像', e);
    const {
      avatarUrl
    } = e.detail
    this.setData({
      ['userInfo.avatar']: avatarUrl
    })
  },

获取昵称

xml
  <input type="nickname" class="name-input" name="nickname" value="{{userInfo.nickName||''}}" bindchange="onInput" placeholder="请输入昵称" />
js
// 输入昵称
  onInput(e) {
    const {
      value
    } = e.detail
    console.log('输入昵称', value);
    this.setData({
      ['userInfo.nickName']: value
    })
  },
上一篇 下一篇

猜你喜欢

热点阅读