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; 才能阻止
原文地址:https://www.cnblogs.com/tianmiaogongzuoshi/p/11063660.html
时间: 2024-10-08 08:15:49