elementUI 上傳文件圖片大小加了限制后 仍然上傳了


https://blog.csdn.net/chanlingmai5374/article/details/80558444  看了這位老哥的說法 在看看文檔 才發現自己沒認真看文檔

<el-upload
          :beforeUpload="beforeAvatarUploadPdf"                  
</el-upload>

  

 
 
 
 
 
beforeAvatarUploadPdf(file){
    var testmsg=file.name.substring(file.name.lastIndexOf('.')+1)                
                const extension = testmsg === 'pdf' ||  testmsg === 'PDF';
            
                const isLt50M = file.size / 1024 / 1024 < 50
                if(!extension ) {
                    this.$message({
                        message: '上傳文件只能是pdf格式!',
                        type: 'error'
          });
          return false;//必須加上return false; 才能阻止
                }
                if(!isLt50M) {
                    this.$message({
                        message: '上傳文件大小不能超過 50MB!',
                        type: 'error'
          });
         return false;
                }
                return extension ||  isLt50M
}

必須加上return false; 才能阻止


免責聲明!

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



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