<el-upload
v-if="activeUsage.name==='上传图片'"
class="avatar-uploader"
action="#"
:show-file-list="false"
:on-change="handleAvatarChange"
:before-upload="beforeAvatarUpload"
:auto-upload="false"
accept=".jpg,.jpeg,.png"
>
<img v-if="imageUrl" :src="imageUrl" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon" />
</el-upload>
handleAvatarChange(file) {
console.log(file)
this.imageUrl = URL.createObjectURL(file.raw)
},
beforeAvatarUpload(file) {
const types = ['image/jpeg', 'image/jpg', 'image/png']
const isImage = types.includes(file.type)
const isLt2M = file.size / 1024 / 1024 < 2
if (!isImage) {
this.$message.error('上传图片只能是 JPG、JPEG、PNG 格式!')
}
if (!isLt2M) {
this.$message.error('上传头像图片大小不能超过 2MB!')
}
return isImage && isLt2M
},