因为 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
},
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。