注意:一定要使用ref,方便后面的方法调用
<el-upload
ref="uploadCpRef"
action="#"
list-type="picture-card"
:auto-upload="false"
:on-change="cpImgChange"
:file-list="tableData.cpMainImg">
</el-upload>
关键代码:this.$refs.XXX.uploadFiles.splice(this.$refs.XXX.uploadFiles.indexOf(), 1);
cpImgChange(file, fileList){
const isIMG = ['jpeg', 'png', 'gif', 'jpg'].includes(file.raw.type.split('/')[1]);
if (!isIMG) {
this.$refs.uploadCpRef.uploadFiles.splice(this.$refs.uploadCpRef.uploadFiles.indexOf(), 1);
this.$message.error('上传图片只能是jpeg/png/gif/jpg格式!');
}
},
注:本人前端小白 ,如有不对的地方还请多多指教