个人信息——头像更换(拍照或相册上传)~ 微信小程序

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

图像点击触发事件:

<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);
}
})
}
})
}
})
上一篇:七牛--关于图片上传方向不统一的问题--主要关于图片EXIF信息中旋转参数Orientation的理解


下一篇:python+unittest+requests实现接口自动化