小程序中头像昵称填写

官方文档

参考小程序用户头像昵称获取规则调整公告

新的小程序版本不能通过wx.getUserProfile和wx.getUserInfo获取用户信息

html 复制代码
      <van-field label="{{Avatar}}" label-class="field-label" right-icon-class="field-right-icon-class"
        input-class="field-input" input-align="right" readonly>
        <view slot="right-icon" class="right-icon">
          <button class="right-icon__btn" open-type="chooseAvatar" bindchooseavatar="getAvater"
            style="border: 1px solid;"></button>
          <image class="right-icon__avatar" src="{{userinfo.avatarUrl}}" />
        </view>
      </van-field>
      <van-field label="{{Name}}" required label-class="field-label" error-message="{{nicknameMessage}}" input-class="field-input" input-align="right">
        <input slot="input" value="{{ userinfo.nickname }}"  type="nickname" class="right-input field-input" placeholder="{{PleaseInput}}{{Name}}"
        placeholder-style="color: #c4c4c4"  maxlength="{{30}}" bind:input="changeName" bind:change="changeName" />
      </van-field>

注意昵称填写,同时绑定了input和change事件(input是用户输入时触发,change是直接选择微信昵称时触发)

javascript 复制代码
    getAvater(event) {
        console.log(9, event);
        console.log('event', event.detail.avatarUrl);
        this.setData({
            changeAvatar: true,
            userinfo: Object.assign({}, this.data.userinfo, {
                avatarUrl: event.detail.avatarUrl,
            })
        })
    },

    changeName(e) {
        console.log('e.detail.value', e.detail.value);
        this.setData({
            userinfo: Object.assign({}, this.data.userinfo, {
                nickname: e.detail.value
            }),
            nicknameMessage: !e.detail.value ? this.data.PleaseInput + this.data.Name : '',
        })
    },
相关推荐
汝生淮南吾在北7 小时前
SpringBoot3+Vue3小区物业报修系统+微信小程序
微信小程序·小程序·vue·毕业设计·springboot·课程设计·毕设
汤姆yu9 小时前
基于微信小程序的自习室座位预约系统
微信小程序·小程序
2501_9151063212 小时前
HTTP 协议详解,HTTP 协议在真实运行环境中的表现差异
网络·网络协议·http·ios·小程序·uni-app·iphone
焦糖玛奇朵婷13 小时前
扭蛋机小程序:线上扭蛋机模式发展新形势[特殊字符]
大数据·数据库·程序人生·小程序·软件需求
云云只是个程序马喽14 小时前
海外短剧系统开发核心功能设计及上线材料准备
小程序·php
2501_9160074714 小时前
iOS与Android符号还原服务统一重构实践总结
android·ios·小程序·重构·uni-app·iphone·webview
全栈软件开发14 小时前
最新壁纸头像小程序系统源码 带流量主
小程序
00后程序员张16 小时前
fastlane 结合 appuploader 命令行实现跨平台上传发布 iOS App
android·ios·小程序·https·uni-app·iphone·webview
2501_9151063217 小时前
iOS 性能优化这件事,结合多工具分析运行期性能问题
android·ios·性能优化·小程序·uni-app·cocoa·iphone
鲁Q同志17 小时前
微信小程序调用上一页的方法(主包,分包)
微信小程序·小程序