<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 extension = fileName === 'xls'
            const extension2 = fileName=== 'xlsx'
            if(!extension && !extension2) {
                this.$message({
                    message: '上传文件只能是 xls、xlsx格式!',
                    type: 'warning'
                });
            }
 }
GitHub 加速计划 / eleme / element
54.06 K
14.63 K
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:3 个月前 )
c345bb45 7 个月前
a07f3a59 * Update transition.md * Update table.md * Update transition.md * Update table.md * Update transition.md * Update table.md * Update table.md * Update transition.md * Update popover.md 7 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐