代碼
<el-upload class="upload-box" action="" accept=".ppt,.pdf" :limit='1' :on-change="changeFile" ref="upload" :show-file-list="false" :auto-upload="false"> <el-button :type="form.otherInfo.length>0?'warning':'info'" slot="trigger">{{form.otherInfo.length>0?'重新上傳':'點擊上傳'}}</el-button> <span>格式為ppt/pdf,其他資料小於20MB</span> </el-upload>
changeFile (file, fileList) { console.log('change', file, file.raw) if(file.raw.size>10*1024*1024){ this.$message.warning(`格式為pdf,報名表大小小於10M`) return } if (fileList.length > 0) { this.fileList = [fileList[fileList.length - 1]]//這一步,是 展示最后一次選擇文件 } this.sendFile('pdf',file)//上傳文件 this.$refs.upload.clearFiles(); //清空當前 files },
生效