class="upload-demo" accept=".doc, .docx, .xlsx, .xls, .txt, .pdf, .html, .htm" action="https://jsonplaceholder.typicode.com/posts/" drag :multiple="false" :show-file-list="false" :before-upload="changeUpload" :on-success="successUpload" :on-error="errorUpload" :on-progress="progressUpload" > 支持格式: “doc”,“.docx”,“.pdf”,“.xls”,“.xlsx”,“.txt”
,“.html”,“.htm”,文件大小不超过 5MB
vue使用element-ui的上传组件,加了accept=".doc, .docx, .xlsx, .xls, .txt, .pdf, .html, .htm"文件类型限制后before-upload中的文件判断校验在拖文件进入时不会执行,但是点击添加文件的时候还是会执行,大佬帮忙看看怎么回事
js代码:
changeUpload (files) {
let filesType = files.name.split('.')[1];
const typeList = ['doc', 'docx', 'xlsx', 'xls', 'txt', 'pdf', 'html', 'htm'];
const sizeOff = (files.size / 1024 / 1024) <= 5;
let typeOff = typeList.some((item) => {
return filesType == item
});
if (!typeOff){
this.$message.error('上传简历格式不正确!');
this.disableStyle(false);
};
if (!sizeOff){
this.$message.error('文件大小不超过5MB!');
this.disableStyle(false);
};
return typeOff && sizeOff;
}