<el-upload v-model:file-list="upload.fileList" :action="upload.action" list-type="picture-card"
:before-upload="upload.before" :on-success="upload.success" limit :on-preview="upload.proview"
:data-fileListCount="upload.fileList.length" :name="upload.name" :on-remove="upload.remove">
<el-dialog v-model="upload.dialogVisible" :close-on-click-modal="false" :close-on-press-escape="false"
<img w-full :src="upload.dialogImageUrl" alt="" style="width:100%;height:100%" />
import { ref, reactive } from 'vue'
import { Plus } from '@element-plus/icons-vue'
import baseUrl from '@/api/baseUrl.js'
const props = defineProps({
const emit = defineEmits(['getImageUrl'])
const upload = reactive({
fileList: props.imageUrl ? [{ url: props.imageUrl }] : [],
const type = ['image/png', 'image/jpeg', 'image/gif'];
if (!type.includes(file.type)) {
ElMessage.error('不支持该类型文件')
upload.dialogImageUrl = url;
upload.dialogVisible = true;
success: (res, uploadFile, uploadFiles) => {
if (res.url && res.code === 1) {
emit('getImageUrl', res.url, uploadFile.url);
ElMessage({ type: 'warning', message: res.msg });
emit('getImageUrl', '', '');
remove: (file, files) => {
emit('getImageUrl', '', '');
<style scope lang="scss">
[data-fileListCount='1'] {
.el-upload--picture-card {
display: none !important;
页面使用:
import UploadAvatar from '@/components/UploadAvatar/index.vue';
模版区使用:
<UploadAvatar @getImageUrl="getImageUrl" :imageUrl="table.image" />