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) },