DreamerLeaf

微信小程序中 在用户信息中关于用户头像更换(拍照或相册上传)功能实现。

图像点击触发事件:

<image src=\'{{personImage}}\' bindtap=\'changeAvatar\' ></image>
Page({
 data:{},  changeAvatar:function(){ const _this = this; wx.chooseImage({ count: 1, sizeType: [\'original\', \'compressed\'], sourceType: [\'album\', \'camera\'], success(res) { // tempFilePath可以作为img标签的src属性显示图片 const tempFilePath = res.tempFilePaths[0]; _this.setData({ personImage: tempFilePath }) wx.uploadFile({ url: config.UPLOADFILE, //图片上传至开发服务器接口 filePath: tempFilePath, name: \'file\', formData: {}, success(res) { const data = res.data; console.log(data); } }) } }) } })

 

分类:

技术点:

相关文章:

  • 2021-08-23
  • 2021-11-07
  • 2021-12-04
  • 2021-11-04
  • 2022-12-23
  • 2021-11-24
猜你喜欢
  • 2021-12-03
  • 2021-10-07
  • 2021-11-18
  • 2021-05-19
  • 2021-10-16
  • 2022-12-23
相关资源
相似解决方案