From 636a723dfc0763b8f57a723bc48003da198af7b6 Mon Sep 17 00:00:00 2001 From: "Ray.Hao" <1490493387@qq.com> Date: Tue, 28 Jan 2025 23:59:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20:recycle:=20=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BB=A3=E7=A0=81=E9=87=8D=E6=9E=84=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Upload/ImageUpload.vue | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/components/Upload/ImageUpload.vue b/src/components/Upload/ImageUpload.vue index 26064389..08aed9ab 100644 --- a/src/components/Upload/ImageUpload.vue +++ b/src/components/Upload/ImageUpload.vue @@ -108,14 +108,6 @@ const props = defineProps({ type: String, default: "image/*", }, - /** - * 支持的文件类型,默认支持所有图片格式 - * eg:['png','jpg','jpeg','gif'] - */ - supportFileType: { - type: Array, - default: () => [], - }, /** * 自定义样式 @@ -150,6 +142,7 @@ const viewVisible = ref(false); const initialIndex = ref(0); const fileList = ref([]); // 默认上传文件 +const uploadedImgUrls = ref([]); // 已上传的图片 const previewImgUrls = ref([]); // 添加一个ref来引用el-upload组件 @@ -254,13 +247,12 @@ function handleUpload(options: UploadRequestOptions) { */ const handleSuccess = (fileInfo: FileInfo) => { ElMessage.success("上传成功"); - valFileList.value.push(fileInfo.url); - if (!props.multiple) { - emit("update:modelValue", fileInfo.url); - emit("change", fileInfo.url); + const { url } = fileInfo; + uploadedImgUrls.value.push(url); + if (props.multiple && Array.isArray(modelValue.value)) { + modelValue.value.push(url); } else { - emit("update:modelValue", valFileList.value); - emit("change", valFileList.value); + modelValue.value = url; } return; };