vue Element文件上传校验大小


<el-upload
                  v-loading="uploadLoading"
                  ref="replyUpload"
                  :before-upload="beforeUpload"
                  :http-request="uploadFile"
                  :data="{ tp: '2' }"
                  class="upload-demo"
                  action="api_ws/api/Contract/AttachmentUpload"
                  align="center"
                  style="float:left"
                >
                  <el-button size="small" type="primary">点击上传</el-button>
                  <label slot="tip" class="el-upload__tip">
                    上传文件不能超过5个,上传文件大小不超过15MB
                  </label>
                  <!-- <i class="el-icon-upload"></i>
                  <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>-->
                </el-upload>
 
 
// 上传前的校验
    beforeUpload(file) {
      this.uploadLoading = true;
      // 校验文件大小
      var result = file.size / 1024 / 1024 < 15 ? "1" : "0";
      if (result === "0") {
        this.$message({
          message: "上传文件大小不能超过15MB!",
          type: "error"
        });
        this.uploadLoading = false;
        return false;
      }
      return true;
    },


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM