上代碼: :beforeUpload="beforeAvatarUpload" 底下有方法重要在這裡:methods裡面寫beforeAvatarUpload這個方法 想要什麼限制加什麼限制就好。 ...
上代碼:
<div class="filebox"> <el-upload class="upload-demo" :action="url" :on-preview="handlePreview" :on-remove="handleRemove"
multiple :limit="limitnum" :on-exceed="handleExceed" :file-list="fileList" :beforeUpload="beforeAvatarUpload"> <el-button size="mini" type="primary">點擊上傳</el-button> <div slot="tip" class="el-upload__tip">只能上傳jpg/png文件,且不超過500kb</div> </el-upload> </div>
:beforeUpload="beforeAvatarUpload" 底下有方法重要在這裡:
methods裡面寫beforeAvatarUpload這個方法
beforeAvatarUpload(file) { var testmsg=file.name.substring(file.name.lastIndexOf('.')+1) const extension = testmsg === 'xls' const extension2 = testmsg === 'xlsx' const isLt2M = file.size / 1024 / 1024 < 10 if(!extension && !extension2) { this.$message({ message: '上傳文件只能是 xls、xlsx格式!', type: 'warning' }); } if(!isLt2M) { this.$message({ message: '上傳文件大小不能超過 10MB!', type: 'warning' }); } return extension || extension2 && isLt2M }
想要什麼限制加什麼限制就好。