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