700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > vue 上传文件限制格式——判断文件类型

vue 上传文件限制格式——判断文件类型

时间:2024-03-08 11:54:16

相关推荐

vue 上传文件限制格式——判断文件类型

①截取文件名后缀

<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(/.+\./, "")

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。