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

图像点击触发事件:

image src='{{personImage}}' bindtap='changeAvatar' /imagePage({ 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);           }         })         }    })  }})

 

TAG标签: 微信小程序修改头像

http://www.xiaochengxub.com/read-104873.html