API:wx.uploadFile,
基础库版本:2.19.4
版本:开发版,微信开发者工具预览
组件内调用
changeImage: async function (e) {
if (this.data.editable) {
chooseImageToUpload(e.currentTarget.dataset.name).then(res => {
console.log(res);
this.setData({
imageUrl: res.url
});
this.triggerEvent('changeImage', res)
})
return false;
}
}
chooseImageToUpload封装:
export function chooseImageToUpload(label) {
return new Promise((resolve, reject) => {
wx.chooseImage({
count: 1,
success: tempFile => {
wx.uploadFile({
url: 'https://jiafeimaoapp.com/app/file/upload',
filePath: tempFile.tempFilePaths[0],
name: 'normalServiceImage',
success: res => {
let result = JSON.parse(res.data);
let url = result.data;
let msg = {
url: url,
label: label
};
resolve(msg);
},
fail: res => {
console.log(res);
reject(res);
}
})
}
});
return false;
})
}
页面内调用绑定函数
//点击认证图片,修改认证用图片
changeVerifyImage(e) {
console.log(e);
},
麻烦大佬们帮忙看一下,这个问题会导致页面本身已经修改的Data里面的信息丢失,触发页面刷新之后偶尔还可以保留之前修改过的值