微信小程序chooseAvatar获取头像

1.wxml页面

  <button open-type="chooseAvatar" bindchooseavatar="getAvatar">
 </button>

2.js

拿临时地址上传到后台

  getAvatar(e) {

    console.log(e)
    var that = this
    wx.uploadFile({
      url: '上传地址',
      filePath: e.detail.avatarUrl,
      name: "avatarfile",
      formData: {
        'user': 'test'
      },
      header: {
        "Content-Type": "multipart/form-data"
      },
      method: 'post',
      success: function (res) {

        console.log(res)
        wx.showToast({
          title: "上传成功",
          icon: "none",
          duration: 1500
        })
        that.setData({
          avatarUrl: res.data
        })


      },
      fail: function (err) {
        wx.showToast({
          title: "上传失败",
          icon: "none",
          duration: 2000
        })
      },
      complete: function (result) {}
    })
    
  },

3.如果没有弹窗,调整一下版本

相关推荐

  1. 程序--注册时获取头像

    2024-01-09 05:42:01       49 阅读
  2. 程序自定义头部

    2024-01-09 05:42:01       31 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-09 05:42:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-09 05:42:01       101 阅读
  3. 在Django里面运行非项目文件

    2024-01-09 05:42:01       82 阅读
  4. Python语言-面向对象

    2024-01-09 05:42:01       91 阅读

热门阅读

  1. Golang学习之路一六运算符

    2024-01-09 05:42:01       58 阅读
  2. golang利用alpn机制实现优先以http2协议访问服务端

    2024-01-09 05:42:01       57 阅读
  3. 前端面试--moka

    2024-01-09 05:42:01       68 阅读
  4. spring之AOP源码分析上

    2024-01-09 05:42:01       58 阅读
  5. 谈谈Mongodb insertMany的一些坑

    2024-01-09 05:42:01       50 阅读