<el-upload
ref="upload"
:accept="上传什么类型的文件"
action="faker"
:limit="1"
:show-file-list="false"
:on-change="handleChange"
:on-preview="handlePreview"
:on-remove="handleRemove"
:file-list="fileList"
:auto-upload="false"
:before-upload="beforeUpload"
>
<el-button size="small">导入文件</el-button>
</el-upload>
handleChange(file,fileList){
let testmsg=file.name.substring(file.name.lastIndexOf('.')+1);
const extension = testmsg === 'xls'
const extension2 = testmsg === 'xlsx'
if(!extension && !extension2){
this.$message.warning("上传文件只能是 xls、xlsx格式");
window.setTimeout(() => this.$refs.upload.clearFiles(), 1000);
return
}
const isLt2M = file.size / 1024 / 1024 < fileManagementFileSize
if(!isLt2M){
this.$message.warning('上传文件大小不能超过20MB!');
window.setTimeout(() => this.$refs.upload.clearFiles(), 1000);
return
}
this.fileList = [];
if (fileList.length > 0) {
this.fileList = [file];//获取文件流
const m=this.$message.success('正在导入……','el-icon-loading',0)
let formData = new FormData();
formData.append("file", this.fileList[0].raw);
m.close();
}
},
handleRemove(file, fileList) {
},
handlePreview(file, fileList) {
},
beforeUpload(file, fileList) {
}
标签:文件,const,testmsg,fileList,导入,file,message,上传
From: https://blog.csdn.net/weixin_44201656/article/details/141364819