阅读:3767回复:1
Element如何设置Upload上传文件类型,element-ui upload accept="" 不起作用
<el-upload
class="upload-demo" ref="upload" drag action="https://jsonplaceholder.typicode.com/posts/" :limit="1" accept=".xls,.xlsx" :on-preview="handlePreview" :on-exceed="handleExceed" :on-remove="handleRemove" :before-upload="beforeAvatarUpload" :file-list="fileList" :auto-upload="false"> <i class="el-icon-upload"></i> <div class="el-upload__text">将发货表单拖到此处,或<em>点击选择</em></div> <div style="line-height: 25px" class="c-9">每次只能导入一个文件</div> </el-upload> 然而,发现 accept=".xls,.xlsx" 并没用过滤掉其他文件类型 还得自己加个判断: beforeAvatarUpload(file){ let fileName=file.name.substring(file.name.lastIndexOf('.')+1) const extension1 = fileName === 'xls' const extension2 = fileName=== 'xlsx' const extension3 = fileName === 'doc' const extension4 = fileName === 'docx' const extension5 = fileName === 'jpg' const extension6 = fileName === 'png' const extension7 = fileName === 'gif' if(!extension1 && !extension2 && !extension3 && !extension4 && !extension5 && !extension6 && !extension7) { this.$message({ message: '上传文件只能是 xls、xlsx、doc、docx、jpg、png、gif 格式!', type: 'warning' }); } } |
|
沙发#
发布于:2022-07-26 16:01
|
|