<el-upload
v-model:file-list="fileList"
action="地址"
:before-upload="Acceps"
>
<el-icon><Picture /></el-icon>
</el-upload>
const Acceps = async (file) => {
console.log(file)
// 文件类型校验
var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
const extension =
testmsg === 'jpg' || testmsg === 'png' || testmsg === 'jpeg' || testmsg === 'gif'
if (!extension) {
ElMessage({
message: '上传文件只能是.jpg、.png、.jpeg、.gif 格式的图片!',
type: 'warning'
})
// 文件大小校验
let size200M = file.size / 1024 / 1024 < 200
if (!size200M) {
ElMessage({
message: '上传大小不能超过20M',
type: 'warning'
})
return false
}
}
return extension
}