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

因为 before-upload 是指在文件上传之前、文件已被选中,但还没上传的时候触发,而设置了 :auto-upload="false" 后,文件上传事件不被再次调用,,所以 before-upload 不生效,所以,限制图片大小和格式的时候,需绑定在 :on-change 里面
 
        反馈数据导入 *
        浏览
      
 // 反馈数据导出
    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
    },

你可能感兴趣的:(ElementUI el-upload上传图片限制, before-upload 不生效问题)