因为 before-upload 是指在文件上传之前、文件已被选中,但还没上传的时候触发,而设置了 :auto-upload="false" 后,文件上传事件不被再次调用,,所以 before-upload 不生效,所以,限制图片大小和格式的时候,需绑定在 :on-change 里面
<el-upload class="upload-demo uploadTwo" ref="fileUploadRef" :action="fileUrl + 'order/mdm/partpredictioncoord/import'" :file-list="fileUploadList" :auto-upload="false" :headers="header" name="uploadFile" :limit="1" multiple :on-change="beforeFeedBackExport" :on-success="fileUploadSuccess">
<span style="float: left; line-height: 32px; padding-right: 10px">反馈数据导入 <span style="color:red">*</span>:</span>
<el-button slot="trigger" size="small" type="primary" style="float: right;">浏览</el-button>
</el-upload>
// 反馈数据导出
beforeFeedBackExport(file) {
// this.tableFileName = file.name;
let testFile = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase()
const extension = testFile === 'xlsx' || testFile === 'xls';
const isLt2M = (file.size / 1024 / 1024 < 10);
if (!extension) {
this.$message({
message: '上传文件只能是xls/xlsx!',
type: 'warning'
});
this.fileUploadList = []
return false;
}
if (!isLt2M) {
this.$message({
message: "文件大小不可以超过10M",
type: 'warning'
});
this.fileUploadList = []
return false;
}
return (extension) && isLt2M
},