el-upload回显图片后修改图片,已经设置了:file-list属性,能成功回显,问题是如果图片不做修改直接提交,那么原来的图片无法上传到后端,经调试发现是根本没有调用el-upload的上传函数,修改图片后再提交后端就能正常接收。
那如果修改时图片没有被更改,直接提交的话,怎么才能把原来的图片提交上去。
el-upload部分的代码
"题目图片:" prop="picture">
"imgForm"
:multiple="false"
list-type="picture-card"
:class="{hide:hideUpload}"
name="file"
:on-preview="handlePreview"
:on-remove="remove"
:on-change="uploadChange"
:before-upload="beforeUpload"
:http-request="upLoadFile"
:auto-upload="false"
:file-list="headFileList"
>
"el-icon-plus">
修改时回显数据的代码
this.ruleForm = res.data;
if (res.data.picture) {
this.headFileList = [];
this.headFileList.push({url: "../../questionsImages/" + res.data.picture})
this.hideUpload = this.headFileList.length >= this.limitCount;
}
点击提交按钮时调用图片的提交方法 this.$refs.imgForm.submit();
图片的提交方法
upLoadFile(file) {
this.formData.append('file', file.file);
},
已经上传过了,后端一般返回已经存储过的地址http或https开头,所以没有修改的应该不用重新上传了才对,而是返回给后端http地址图片,或者图片id给后端判断
回显有应该没有file文件吗,或者重新上传时,旧图片传id还是什么和后端协商