importSharp 2022-06-28 15:22 采纳率: 53.8%
浏览 508
已结题

使用vue simple uploader做上传文件类型的拦截判断

问题遇到的现象和发生背景

想用Vue simple uploader做一个文件上传的功能,只允许csv和excel文件,但发现上传什么文件都不行

问题相关代码,请勿粘贴截图

html代码

<uploader
        ref="uploader"
        v-loading="loading"
        element-loading-text="正在上传"
        :options="options"
        :autoStart="false"
        :file-status-text="fileStatusText"
        @file-added="onFileAdded"
        @file-success="onFileSuccess"
        @file-progress="onFileProgress"
        @file-error="onFileError"
        @file-removed="fileRemoved"
        class="uploader-ui"
    >
      <uploader-unsupport></uploader-unsupport>
      <uploader-drop>
        <div>
          <uploader-btn
              id="global-uploader-btn"
              ref="uploadBtn"
              v-show="!fileSuccess"
          >
            选择文件
            <i class="el-icon-upload el-icon--right"></i>
          </uploader-btn>
        </div>
      </uploader-drop>
      <uploader-list></uploader-list>
    </uploader>

js

onFileAdded(file) {
      this.loading = true;
      if (
          [
            "text/csv",
            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
          ].indexOf(file.fileType) === -1
      ) {
        this.$message.error("请上传正确的格式");
        file.ignored = true;
      } else {
        this.$message.success("文件格式验证成功!");
        this.$emit("checkFileSuccess", file);
      }
      this.loading = false;
      // videoApi.checkVideoName(file.name).then(response => {
      //     console.log(response)
      //     this.$message.success('文件名称验证' + response.data.msg)
      //     this.$emit('checkFileSuccess', file)
      // }).catch((error) => { 
      //     file.cancel()
      //     console.log('error', error)
      //     this.$message.error('出现文件重名问题,请更换文件名后重试 (' + error.msg + ')')
      // })
    }

运行结果及报错内容
我的解答思路和尝试过的方法

觉得应该是csv或者是excel的content-type不正确,因为试过视频的格式是可以的

我想要达到的结果
  • 写回答

3条回答 默认 最新

  • 王鹏飞的解忧屋 2022-06-28 15:46
    关注
    获得0.75元问题酬金

    你用的是element组件库吗?

    评论

报告相同问题?

问题事件

  • 系统已结题 7月6日
  • 赞助了问题酬金5元 6月28日
  • 创建了问题 6月28日

悬赏问题

  • ¥15 无法输出helloworld
  • ¥15 高通uboot 打印ubi init err 22
  • ¥20 PDF元数据中的XMP媒体管理属性
  • ¥15 R语言中lasso回归报错
  • ¥15 网站突然不能访问了,上午还好好的
  • ¥15 有没有dl可以帮弄”我去图书馆”秒选道具和积分
  • ¥15 semrush,SEO,内嵌网站,api
  • ¥15 Stata:为什么reghdfe后的因变量没有被发现识别啊
  • ¥15 振荡电路,ADS仿真
  • ¥15 关于#c语言#的问题,请各位专家解答!