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