el-upload使用beforeUpload不生效
解决方式如下:
将auto-upload设置成false,用on-change来操作
<el-upload
<el-upload
class="upload-demo"
:action="uploadUrl"
:auto-upload="false"
:on-preview="handlePreview"
:on-remove="handleRemove"
:before-remove="beforeRemove"
:on-success="handleSuccess"
:on-exceed="handleExceed"
:on-change="handleChange"
:file-list="fileList"
:limit="1"
>
async handleChange (file, fileList){
if (file.size / 1024 / 1024 > 5) {
this.fileList = []; //将列表清空
this.$message.warning("上传文件大小不能超过 5MB!");
return false;
}
this.fileList = fileList;
// 传参用的是FormData类型
// 传参用的是FormData类型
let formData = new FormData();
formData.append('file',file.raw); //file类型是binary
formData.append('fileName', file.name);
const res = await infoApi.uploadFile(formData);
},