①截取文件名后缀
<el-uploadaccept=".mdb":limit="1":auto-upload="false":file-list="fileList":show-file-list="false"class="upload-demo"action="":on-change="handleChange" // 文件发生变化时回调><div slot="tip" class="el-upload__tip">只能上传mdb文件</div></el-upload>handleChange(file, fileLists) {// 截取文件名后缀let fileName = file.name;let pos = fileName.lastIndexOf(".");let lastName = fileName.substring(pos, fileName.length);if (lastName.toLowerCase() !== ".mdb") {this.$message.error("文件必须为.mdb类型");// 清空文件列表const newFileList = this.fileList.slice();newFileList.splice(0, 1);this.fileList = newFileList;} else { }
②简便法获取文件类型
let fileType = fileList[0].name.replace(/.+\./, "")