element 文件上傳大小控制


1.頁面代碼

 <el-upload :show-file-list="false" class="upload-demo" :before-upload="beforeUpload"
                        :on-progress="onProgress" :on-success="onSuccess" :on-error="onError" action="/api/upload">
                        <el-button size="small" type="primary">點擊上傳</el-button>
                  </el-upload>

2. 在before-upload事件中判斷文件大小,不符合返回false

  beforeUpload(file) {

                        let fileObj = {
                              name: file.name,
                              size: file.size,
                              status: "開始上傳",
                              process: 0,
                              id: file.uid
                        }
                        if (file.size > 100 * 1024 * 1024) {
                              console.log('上傳文件過大', file.size)
                              return false   //必須返回false
                        }
                        this.fileList.push(fileObj)

                  },

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM