ElementUI el-upload上传图片限制, before-upload 不生效问题

因为 before-upload 是指在文件上传之前、文件已被选中,但还没上传的时候触发,而设置了 :auto-upload="false" 后,文件上传事件不被再次调用,,所以 before-upload 不生效,所以,限制图片大小和格式的时候,需绑定在 :on-change 里面
 <el-upload class="upload-demo uploadTwo" ref="fileUploadRef" :action="fileUrl + 'order/mdm/partpredictioncoord/import'" :file-list="fileUploadList" :auto-upload="false" :headers="header" name="uploadFile" :limit="1" multiple :on-change="beforeFeedBackExport" :on-success="fileUploadSuccess">
        <span style="float: left; line-height: 32px; padding-right: 10px">反馈数据导入 <span style="color:red">*</span>:</span>
        <el-button slot="trigger" size="small" type="primary" style="float: right;">浏览</el-button>
      </el-upload>
 // 反馈数据导出
    beforeFeedBackExport(file) {

      // this.tableFileName = file.name;


      let testFile = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase()

      const extension = testFile === 'xlsx' || testFile === 'xls';

      const isLt2M = (file.size / 1024 / 1024 < 10);
      if (!extension) {
        this.$message({
          message: '上传文件只能是xls/xlsx!',
          type: 'warning'
        });
        this.fileUploadList = []
        return false;
      }
      if (!isLt2M) {
        this.$message({
          message: "文件大小不可以超过10M",
          type: 'warning'
        });
        this.fileUploadList = []
        return false;
      }
      return (extension) && isLt2M
    },
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容