Skip to content
Latestv1.0.60

Upload

Upload files by clicking or dragging.

Basic Usage

The most common upload method, supporting multi-selection.

Photo Wall

Suitable for avatars or product images.

Drag & Drop

Directory Upload

Enable folder upload via the directory attribute. Once enabled, only folders can be selected; files within the folder will be flattened and uploaded sequentially.

Manual Upload

Disable automatic upload by setting the auto-upload attribute to false, then manually trigger upload by calling the submit method of the component instance.

Image List Mode

Custom Upload

The http-request attribute allows you to completely customize the upload implementation logic, such as using your own axios instance or connecting to a specific cloud storage SDK.

Download & Custom Download

The download button can be displayed via the show-download attribute. Clicking the download button will trigger the download event.

TIP

About Download Functionality: The component has built-in mandatory download logic based on Blob. However, please note that if the file is stored on a third-party server without Cross-Origin Resource Sharing (CORS) enabled, the browser may downgrade to "Open in new window preview" mode due to security policies. It is recommended to ensure that the static resource server has the Access-Control-Allow-Origin response header configured in production environments.

Advanced Business: Validation & Compression

In actual business scenarios, we often need to check file size and type before uploading, or even compress images.

Custom Thumbnail

The thumbnail-request attribute gives you complete control over preview image generation logic. For example, performing quality compression on large images before displaying them, or returning different default placeholders based on file extensions.

Avatar Upload (Single Replacement)

A very practical case. Limit the upload quantity via limit="1" and use the exceed event to replace the old image with a new one directly for an "Avatar Upload" effect.

Photo Wall Position & Preview Download

The trigger-position attribute controls the position of the upload button relative to the list (top | bottom | left | right). In picture-card mode, after enabling show-download, a download button will also appear when hovering over the preview image.

Overwrite Previous File

By setting limit="1" and listening to the exceed event, you can achieve the effect of automatically replacing the previous file when a new file is selected.

File Type Icons

The component automatically matches corresponding icons based on file extensions (Word, Excel, PDF, video, audio, text, etc.). For unknown types, it displays an "Attachment" icon by default. You can also completely customize it via the file-icon slot.

Custom File List Slot

Use the file scoped slot to completely customize each item in the file list, satisfying more complex UI requirements.

File Preview Feature

By listening to the preview event, you can implement preview logic when clicking on a file. For image files, the component already has a built-in viewerjs preview engine.

Use in Nuxt

YhUpload can be rendered in Nuxt pages, but preview, thumbnail generation, drag-and-drop, and file reading rely on browser APIs. In SSR scenarios, keep those interactive parts inside <ClientOnly> or trigger them only after the client has mounted.

vue
<template>
  <ClientOnly>
    <yh-upload action="/api/upload">
      <yh-button type="primary">Nuxt Upload File</yh-button>
    </yh-upload>
  </ClientOnly>
</template>

API

Props

AttributeDescriptionTypeDefault
v-model:file-listUploaded file listUploadFile[][]
actionUpload target URLstring''
methodUpload HTTP methodstring'POST'
headersSet upload request headersRecord<string, string>{}
dataAdditional parameters with uploadRecord<string, unknown>{}
nameUpload file field namestring'file'
multipleWhether to support multi-selectionbooleanfalse
dragWhether to enable drag-and-drop uploadbooleanfalse
acceptAccepted file typesstring''
showFileListWhether to show the uploaded file listbooleantrue
limitMaximum number of files allowednumber-
autoUploadWhether to upload immediately after selectionbooleantrue
listTypeFile list display style'text' | 'picture' | 'picture-card''text'
withCredentialsSupport sending cookie credentialsbooleanfalse
httpRequestOverride default upload behavior(options: UploadRequestOptions) => Promise<unknown> | void-
beforeUploadHook before file is uploaded(file: UploadRawFile) => boolean | Promise<boolean | Blob>-
beforeRemoveHook before file is removed(file: UploadFile, fileList: UploadFile[]) => boolean | Promise<boolean>-
disabledWhether to disable uploadbooleanfalse
thumbnailRequestCustom thumbnail generation logic(file: UploadRawFile) => Promise<string> | string-
maxSizeFile size limit (KB)number-
directoryWhether to enable folder upload. Flattened files within folders will be processed.booleanfalse
showDownloadWhether to show the download buttonbooleanfalse
triggerPositionTrigger position relative to the list'top' | 'bottom' | 'left' | 'right''top'
fileIconCustom file icon or icon generation functionstring | ((file: UploadFile) => string)-
crossoriginNative attribute crossorigin'anonymous' | 'use-credentials' | ''-
themeOverridesComponent-level theme overridesComponentThemeVarsundefined

Events

NameDescriptionParameters
update:fileListTriggered when the file list is updated(fileList: UploadFile[])
changeTriggered when file status changes(file: UploadFile, fileList: UploadFile[])
successTriggered on successful upload(response: unknown, file: UploadFile, fileList: UploadFile[])
errorTriggered on upload failure(error: Error, file: UploadFile, fileList: UploadFile[])
progressTriggered when upload progress changes(event: UploadProgressEvent, file: UploadFile, fileList: UploadFile[])
removeTriggered when a file is removed(file: UploadFile, fileList: UploadFile[])
previewTriggered on clicking file preview(file: UploadFile)
downloadTriggered on clicking file download(file: UploadFile)
exceedTriggered when selected files exceed limit(files: File[], fileList: UploadFile[])

Slots

NameDescriptionScope
defaultContent to trigger upload-
triggerElement to trigger selection (non-drag mode)-
tipTip or description text-
fileCustom file list item content{ file: UploadFile }
file-iconCustom file type icon{ file: UploadFile }

Expose

MethodDescriptionParameters
submitManually upload the pending file list-
triggerInputManually evoke the file selection box-
handleRemoveManually remove a specific file(file: UploadFile)
handlePreviewManually trigger file preview(file: UploadFile)
handleDownloadManually trigger file download(file: UploadFile)
handleFilesManually add and process file list(files: File[] | FileList)

Theme Variables

YhUpload supports themeOverrides. The stylesheet directly consumes the following upload-specific CSS variables, while related colors still inherit from the shared theme token system:

VariableDescriptionDefault
--yh-upload-dragger-bgDrag area background colorvar(--yh-bg-color)
--yh-upload-dragger-borderDrag area border colorvar(--yh-border-color-light)
--yh-upload-item-bgFile list item background colorvar(--yh-fill-color-blank)
--yh-upload-progress-bgProgress bar colorvar(--yh-color-primary)
--yh-upload-error-bgError item background colorvar(--yh-color-danger-light-9)
--yh-upload-error-hover-bgError item hover background colorvar(--yh-color-danger-light-7)

Type Exports

NameDescription
YhUploadPropsComponent props type
YhUploadEmitsComponent emits type
YhUploadSlotsComponent slots type
YhUploadExposeComponent expose type
YhUploadFileUploaded file type
YhUploadRawFileRaw file type
YhUploadProgressEventUpload progress event type
YhUploadRequestOptionsUpload request options type
YhUploadStatusUpload status union
YhUploadInstanceComponent instance type

Released under the MIT License.