diff --git a/packages/vant/src/uploader/README.md b/packages/vant/src/uploader/README.md index d54d68e33..f9d241334 100644 --- a/packages/vant/src/uploader/README.md +++ b/packages/vant/src/uploader/README.md @@ -393,6 +393,7 @@ Use [ref](https://vuejs.org/guide/essentials/template-refs.html) to get Uploader | --- | --- | --- | --- | | closeImagePreview | Close full screen image preview | - | - | | chooseFile | Trigger choosing files, works with the user action context only because of browser security | - | - | +| reuploadFile `4.9.3` | Trigger choosing files, choosing a new file will overwrite the previously uploaded file, works with the user action context only because of browser security | _index: number_ | - | ### Types diff --git a/packages/vant/src/uploader/README.zh-CN.md b/packages/vant/src/uploader/README.zh-CN.md index 26ad05982..89593eb0e 100644 --- a/packages/vant/src/uploader/README.zh-CN.md +++ b/packages/vant/src/uploader/README.zh-CN.md @@ -416,6 +416,7 @@ before-read、after-read、before-delete 执行时会传递以下回调参数: | --- | --- | --- | --- | | closeImagePreview | 关闭全屏的图片预览 | - | - | | chooseFile | 主动调起文件选择,由于浏览器安全限制,只有在用户触发操作的上下文中调用才有效 | - | - | +| reuploadFile `4.9.3` | 主动调起文件选择,选择新文件后将覆盖原先上传的文件,由于浏览器安全限制,只有在用户触发操作的上下文中调用才有效 | _index: number_ | - | ### 类型定义 diff --git a/packages/vant/src/uploader/Uploader.tsx b/packages/vant/src/uploader/Uploader.tsx index 0f7c4f8d0..7c43dadab 100644 --- a/packages/vant/src/uploader/Uploader.tsx +++ b/packages/vant/src/uploader/Uploader.tsx @@ -279,11 +279,12 @@ export default defineComponent({ emit('delete', item, getDetail(index)); }; - const reuploadImage = (index: number) => { + const reuploadFile = (index: number) => { isReuploading.value = true; reuploadIndex.value = index; nextTick(() => chooseFile()); }; + const onInputClick = () => { if (!isReuploading.value) { reuploadIndex.value = -1; @@ -319,7 +320,7 @@ export default defineComponent({ } onDelete={() => deleteFile(item, index)} onPreview={() => previewImage(item)} - onReupload={() => reuploadImage(index)} + onReupload={() => reuploadFile(index)} {...pick(props, ['name', 'lazyLoad'])} {...previewData} /> @@ -335,12 +336,7 @@ export default defineComponent({ const onClickUpload = (event: MouseEvent) => emit('clickUpload', event); const renderUpload = () => { - if (props.modelValue.length >= +props.maxCount && !props.reupload) { - return; - } - - const hideUploader = - props.modelValue.length >= +props.maxCount && props.reupload; + const lessThanMax = props.modelValue.length < +props.maxCount; const Input = props.readonly ? null : ( @@ -371,7 +367,7 @@ export default defineComponent({ return (