From 6f74d77da9cbe89da5eb18cd07ed57ebabcaae95 Mon Sep 17 00:00:00 2001 From: ShuGang Zhou Date: Fri, 13 Oct 2023 20:17:54 -0500 Subject: [PATCH] fix(Uploader): multiple reupload only choose one & cancel choose problem (#12359) * fix(Uploader): multiple reupload only choose one & cancel chose problem * fix(Uploader): multiple reupload only choose one & cancel chose problem * fix(Uploader): refactor code * fix(Uploader): refactor code --- packages/vant/src/uploader/Uploader.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/vant/src/uploader/Uploader.tsx b/packages/vant/src/uploader/Uploader.tsx index e8b95001d..0f7c4f8d0 100644 --- a/packages/vant/src/uploader/Uploader.tsx +++ b/packages/vant/src/uploader/Uploader.tsx @@ -5,6 +5,7 @@ import { onBeforeUnmount, type PropType, type ExtractPropTypes, + nextTick, } from 'vue'; // Utils @@ -104,6 +105,7 @@ export default defineComponent({ const inputRef = ref(); const urls: string[] = []; const reuploadIndex = ref(-1); + const isReuploading = ref(false); const getDetail = (index = props.modelValue.length) => ({ name: props.name, @@ -278,9 +280,15 @@ export default defineComponent({ }; const reuploadImage = (index: number) => { - // eslint-disable-next-line no-use-before-define - chooseFile(); + isReuploading.value = true; reuploadIndex.value = index; + nextTick(() => chooseFile()); + }; + const onInputClick = () => { + if (!isReuploading.value) { + reuploadIndex.value = -1; + } + isReuploading.value = false; }; const renderPreviewItem = (item: UploaderFileListItem, index: number) => { @@ -344,6 +352,7 @@ export default defineComponent({ multiple={props.multiple && reuploadIndex.value === -1} disabled={props.disabled} onChange={onChange} + onClick={onInputClick} /> );