<
el-upload
:before-upload="beforeUpload"
</el-upload>
beforeUpload(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
}
联系客服