diff --git a/docs/en-US/component/upload.md b/docs/en-US/component/upload.md index c226250ea2..f8096c2fed 100644 --- a/docs/en-US/component/upload.md +++ b/docs/en-US/component/upload.md @@ -15,6 +15,14 @@ upload/basic ::: +## Cover previous file + +:::demo Set `limit` and `on-exceed` to automatically replace the previous file when select a new file. + +upload/limit-cover + +::: + ## User avatar upload Use `before-upload` hook to limit the upload file format and size. @@ -123,8 +131,9 @@ upload/manual ## Methods -| Methods Name | Description | Parameters | -| ------------ | --------------------------------------------------------------------------------------- | --------------------------- | -| clearFiles | clear the uploaded file list (this method is not supported in the `before-upload` hook) | — | -| abort | cancel upload request | ( file: fileList's item ) | -| submit | upload the file list manually | — | +| Methods Name | Description | Parameters | Default | +| ------------ | ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ----------------------------------------- | +| clearFiles | clear the file list (this method is not supported in the `before-upload` hook). | UploadStatus[] (UploadStatus = 'ready' \| 'uploading' \| 'success' \| 'fail') | ['ready', 'uploading', 'success', 'fail'] | +| abort | cancel upload request | ( file: fileList's item ) | | +| submit | upload the file list manually | — | | +| handleStart | select the file manually | ( file: files' item) | | diff --git a/docs/examples/upload/limit-cover.vue b/docs/examples/upload/limit-cover.vue new file mode 100644 index 0000000000..3f72542faa --- /dev/null +++ b/docs/examples/upload/limit-cover.vue @@ -0,0 +1,39 @@ + + + + select file + + upload to server + + + limit 1 file, new file will cover the old file + + + + + + diff --git a/packages/components/upload/src/useHandlers.ts b/packages/components/upload/src/useHandlers.ts index f9440b9126..60a748931c 100644 --- a/packages/components/upload/src/useHandlers.ts +++ b/packages/components/upload/src/useHandlers.ts @@ -34,9 +34,11 @@ export default (props: IUseHandlersProps) => { uploadRef.value.abort(file) } - function clearFiles(status: UploadStatus[] = ['success', 'fail']) { + function clearFiles( + status: UploadStatus[] = ['ready', 'uploading', 'success', 'fail'] + ) { uploadFiles.value = uploadFiles.value.filter((row) => { - return status.indexOf(row.status) === -1 + return !status.includes(row.status) }) }