Upload 上传
<el-upload accept=".jpg, .jpeg, .png" :before-upload="beforeUpload"></el-upload>
before-upload
:上传前的拦截,可限制文件大小、格式
beforeUpload(file) {
// 上传文件格式、大小限制
const suffix = file.name.substring(file.name.lastIndexOf('.') + 1)
if (
suffix == null ||
suffix === '' ||
(suffix !== 'jpg' && suffix !== 'jpeg' && suffix !== 'png')
) {
this.$message.error('只允许上传jpp、jpeg、png格式的图片')
return false
}
const isLt = file.size < this.maxSize * 1024 * 1024
if (!isLt) {
this.$message.error('上传文件大小不能超过 ' + this.maxSize + 'M!')
}
return isLt
},