第一次写uniapp的项目,遇到了图片上传,其实不难,文档中都有
changeImage(){
let that = this;
uni.chooseImage({
count: 1, //默认9
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], //从相册选择
success: function(res) {
that.imgUrl1 = res.tempFilePaths[0];
uni.getFileSystemManager().readFile({
filePath: that.imgUrl1,
encoding: 'base64',
success: r => {
console.log('r.data', r.data);
that.imgUrl1 = 'data:image/jpeg;base64,' + r.data;
// 'data:image/jpeg;base64,' 这个代码是我后加上去的,要不然就渲染不到页面上去
console.log('that.imgUrl1', that.imgUrl1)
}
})
}
});
}