Upload
A complete file upload system built with Neo-Brutalism design, featuring drag-and-drop, file list management, progress tracking, and error handling.
Preview
基础 text 类型
点击或拖拽文件到此区域上传
document.pdf
1.47 MB
avatar.png
312.5 KB
picture 缩略图列表类型
点击或拖拽文件到此区域上传
sunset.jpg
2.34 MB
picture-card 照片墙类型(最大限制 3 张)
点击或拖拽文件到此区域上传
landscape.jpg
Installation
pnpm dlx brutx-vue@latest add uploadUsage
<script setup>
import { ref } from 'vue'
import { Upload, UploadTrigger, UploadFileList, type UploadFile } from 'brutx-ui-vue'
const fileList = ref<UploadFile[]>([])
async function handleUpload(options) {
// Custom upload implementation
const formData = new FormData()
formData.append('file', options.file)
const response = await fetch('/api/upload', {
method: 'POST',
body: formData,
})
options.onSuccess(response)
}
</script>
<template>
<Upload
v-model:file-list="fileList"
:http-request="handleUpload"
accept="image/*"
:max-size="5 * 1024 * 1024"
>
<template #trigger="{ selectFiles, drag, accept, multiple }">
<UploadTrigger :drag="drag" :accept="accept" :multiple="multiple" @select="selectFiles" />
</template>
<template #file-list="{ files, remove, retry }">
<UploadFileList :files="files" @remove="remove" @retry="retry" />
</template>
</Upload>
</template>Picture Card Type
<script setup>
import { ref } from 'vue'
import { Upload, UploadTrigger, UploadFileList, type UploadFile } from 'brutx-ui-vue'
const fileList = ref<UploadFile[]>([])
</script>
<template>
<Upload
v-model:file-list="fileList"
list-type="picture-card"
:limit="5"
multiple
>
<template #trigger="{ selectFiles, drag, accept, multiple }">
<UploadTrigger :drag="drag" :accept="accept" :multiple="multiple" @select="selectFiles" />
</template>
<template #file-list="{ files, remove }">
<UploadFileList :files="files" list-type="picture-card" @remove="remove" />
</template>
</Upload>
</template>With Hooks
<script setup>
import { ref } from 'vue'
import { Upload, UploadTrigger, UploadFileList, type UploadFile } from 'brutx-ui-vue'
const fileList = ref<UploadFile[]>([])
function beforeUpload(file) {
const isImage = file.type.startsWith('image/')
if (!isImage) {
console.error('只能上传图片文件!')
return false
}
return true
}
async function beforeRemove(file) {
return confirm(`确定删除 ${file.name} 吗?`)
}
</script>
<template>
<Upload
v-model:file-list="fileList"
:before-upload="beforeUpload"
:before-remove="beforeRemove"
>
<template #trigger="{ selectFiles, drag, accept, multiple }">
<UploadTrigger :drag="drag" :accept="accept" :multiple="multiple" @select="selectFiles" />
</template>
<template #file-list="{ files, remove }">
<UploadFileList :files="files" @remove="remove" />
</template>
</Upload>
</template>Sub-components
| Component | Description |
|---|---|
Upload | Root component, manages file list and upload logic |
UploadTrigger | Trigger area for file selection (drag/click) |
UploadFileList | File list container |
UploadFileItem | Single file item with preview, progress, and delete |
API Reference
Upload
| Name | Type | Default | Description |
|---|---|---|---|
fileList | UploadFile[] | undefined | []Factory evaluated per instance | The current file list, available through v-model:fileList. The component syncs external entries by id and preserves in-progress upload state. |
DetailsDeclared typeUploadFile[] | undefined Referenced types UploadFile Type definition — UploadFileexport interface UploadFile {
/** 文件唯一标识符 */
id: string
/** 文件名 */
name: string
/** 文件大小(字节) */
size: number
/** 文件 MIME 类型 */
type: string
/** 上传状态 */
status: 'ready' | 'uploading' | 'success' | 'error' | 'canceled'
/** 上传进度,取值范围 0-100 */
progress: number
/** 文件远程访问 URL 或自定义预览地址 */
url?: string
/** 原始 File 对象,用于上传请求、重试及本地预览生成 */
raw?: File
/** 错误信息 */
error?: UploadError
/** 当前已重试次数 */
retryCount?: number
/** 上传中止控制器 */
abortController?: AbortController
}Default value details
Sourcepackages/ui/src/components/upload/Upload.vue | |||
limit | number | undefined | undefined | Maximum number of files. Once reached, additional files are skipped and the limit error is reported through onError. |
DetailsDeclared typenumber | undefined Default value details
Sourcepackages/ui/src/components/upload/Upload.vue | |||
multiple | boolean | undefined | true | Whether to allow selecting multiple files at once. When false, the picker keeps only the first file. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/upload/Upload.vue | |||
accept | string | undefined | undefined | The accepted file type hint passed to the native picker and used to validate selected files. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/upload/Upload.vue | |||
maxSize | number | undefined | undefined | Maximum size of one file in bytes. Oversized files are skipped and reported through onError. |
DetailsDeclared typenumber | undefined Default value details
Sourcepackages/ui/src/components/upload/Upload.vue | |||
maxRetries | number | undefined | 3 | Maximum retry attempts per file. Once reached, another retry reports an error and does not start an upload. |
DetailsDeclared typenumber | undefined Default value details
Sourcepackages/ui/src/components/upload/Upload.vue | |||
beforeUpload | ((file: File) => boolean | Promise<boolean>) | undefined | undefined | A synchronous or asynchronous check run before a file is added to the list. Returning false skips that file. |
DetailsDeclared type((file: File) => boolean | Promise<boolean>) | undefined Default value details
Sourcepackages/ui/src/components/upload/Upload.vue | |||
beforeRemove | ((file: UploadFile) => boolean | Promise<boolean>) | undefined | undefined | A synchronous or asynchronous confirmation run before removal. Returning false keeps the file in the list. |
DetailsDeclared type((file: UploadFile) => boolean | Promise<boolean>) | undefined Referenced types UploadFile Type definition — UploadFileexport interface UploadFile {
/** 文件唯一标识符 */
id: string
/** 文件名 */
name: string
/** 文件大小(字节) */
size: number
/** 文件 MIME 类型 */
type: string
/** 上传状态 */
status: 'ready' | 'uploading' | 'success' | 'error' | 'canceled'
/** 上传进度,取值范围 0-100 */
progress: number
/** 文件远程访问 URL 或自定义预览地址 */
url?: string
/** 原始 File 对象,用于上传请求、重试及本地预览生成 */
raw?: File
/** 错误信息 */
error?: UploadError
/** 当前已重试次数 */
retryCount?: number
/** 上传中止控制器 */
abortController?: AbortController
}Default value details
Sourcepackages/ui/src/components/upload/Upload.vue | |||
httpRequest | ((options: UploadRequestOptions) => Promise<void>) | undefined | undefined | The asynchronous upload implementation. It receives the file, abort signal, progress callback, and success/error callbacks. Without it, files can still be added to the list but no upload starts. |
DetailsDeclared type((options: UploadRequestOptions) => Promise<void>) | undefined Referenced types UploadRequestOptions Type definition — UploadRequestOptionsexport interface UploadRequestOptions {
/** 待上传的文件 */
file: File
/** 中止信号 */
signal: AbortSignal
/** 进度回调函数,percent 取值范围 0-100 */
onProgress: (percent: number) => void
/** 成功回调函数 */
onSuccess: (response: unknown) => void
/** 失败回调函数 */
onError: (error: UploadError) => void
}Default value details
Sourcepackages/ui/src/components/upload/Upload.vue | |||
listType | "text" | "picture" | "picture-card" | undefined | "text" | Selects the text, picture, or picture-card layout for file entries. |
DetailsDeclared type"text" | "picture" | "picture-card" | undefined Literal values
Default value details
Sourcepackages/ui/src/components/upload/Upload.vue | |||
autoUpload | boolean | undefined | true | Whether to start uploading as soon as a validated file is added. When false, retryUpload can start the upload explicitly. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/upload/Upload.vue | |||
drag | boolean | undefined | true | Enables or disables file dropping on the trigger area. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/upload/Upload.vue | |||
onError | ((error: UploadError, file: UploadFile) => void) | undefined | undefined | Called for file type, size, or count validation failures, upload failures, and retry-limit errors. |
DetailsDeclared type((error: UploadError, file: UploadFile) => void) | undefined Referenced types UploadError Type definition — UploadErrorexport interface UploadError {
/** 错误消息 */
message: string
/** 错误代码 */
code?: string
/** HTTP 状态码 */
status?: number
}UploadFile Type definition — UploadFileexport interface UploadFile {
/** 文件唯一标识符 */
id: string
/** 文件名 */
name: string
/** 文件大小(字节) */
size: number
/** 文件 MIME 类型 */
type: string
/** 上传状态 */
status: 'ready' | 'uploading' | 'success' | 'error' | 'canceled'
/** 上传进度,取值范围 0-100 */
progress: number
/** 文件远程访问 URL 或自定义预览地址 */
url?: string
/** 原始 File 对象,用于上传请求、重试及本地预览生成 */
raw?: File
/** 错误信息 */
error?: UploadError
/** 当前已重试次数 */
retryCount?: number
/** 上传中止控制器 */
abortController?: AbortController
}Default value details
Sourcepackages/ui/src/components/upload/Upload.vue | |||
class | string | undefined | undefined | Custom CSS classes added to the Upload root container. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/upload/Upload.vue | |||
| Name | Signature or type | Description |
|---|---|---|
@update:fileList | [files: UploadFile[]] | Emits a copy of the file list after a file is added or removed to update v-model:fileList. |
DetailsDeclared type[files: UploadFile[]] Referenced types UploadFile Type definition — UploadFileexport interface UploadFile {
/** 文件唯一标识符 */
id: string
/** 文件名 */
name: string
/** 文件大小(字节) */
size: number
/** 文件 MIME 类型 */
type: string
/** 上传状态 */
status: 'ready' | 'uploading' | 'success' | 'error' | 'canceled'
/** 上传进度,取值范围 0-100 */
progress: number
/** 文件远程访问 URL 或自定义预览地址 */
url?: string
/** 原始 File 对象,用于上传请求、重试及本地预览生成 */
raw?: File
/** 错误信息 */
error?: UploadError
/** 当前已重试次数 */
retryCount?: number
/** 上传中止控制器 */
abortController?: AbortController
}Sourcepackages/ui/src/components/upload/Upload.vue | ||
@file-change | [file: UploadFile] | Emitted after a validated file is added to the internal list. Its status is ready, and this occurs before upload completion even when autoUpload is true. |
DetailsDeclared type[file: UploadFile] Referenced types UploadFile Type definition — UploadFileexport interface UploadFile {
/** 文件唯一标识符 */
id: string
/** 文件名 */
name: string
/** 文件大小(字节) */
size: number
/** 文件 MIME 类型 */
type: string
/** 上传状态 */
status: 'ready' | 'uploading' | 'success' | 'error' | 'canceled'
/** 上传进度,取值范围 0-100 */
progress: number
/** 文件远程访问 URL 或自定义预览地址 */
url?: string
/** 原始 File 对象,用于上传请求、重试及本地预览生成 */
raw?: File
/** 错误信息 */
error?: UploadError
/** 当前已重试次数 */
retryCount?: number
/** 上传中止控制器 */
abortController?: AbortController
}Sourcepackages/ui/src/components/upload/Upload.vue | ||
@file-remove | [file: UploadFile] | Emitted after removal completes, provided beforeRemove did not reject it and the file was present in the list. |
DetailsDeclared type[file: UploadFile] Referenced types UploadFile Type definition — UploadFileexport interface UploadFile {
/** 文件唯一标识符 */
id: string
/** 文件名 */
name: string
/** 文件大小(字节) */
size: number
/** 文件 MIME 类型 */
type: string
/** 上传状态 */
status: 'ready' | 'uploading' | 'success' | 'error' | 'canceled'
/** 上传进度,取值范围 0-100 */
progress: number
/** 文件远程访问 URL 或自定义预览地址 */
url?: string
/** 原始 File 对象,用于上传请求、重试及本地预览生成 */
raw?: File
/** 错误信息 */
error?: UploadError
/** 当前已重试次数 */
retryCount?: number
/** 上传中止控制器 */
abortController?: AbortController
}Sourcepackages/ui/src/components/upload/Upload.vue | ||
@file-success | [file: UploadFile] | Emitted when the custom upload implementation calls onSuccess. Canceled uploads do not emit this event. |
DetailsDeclared type[file: UploadFile] Referenced types UploadFile Type definition — UploadFileexport interface UploadFile {
/** 文件唯一标识符 */
id: string
/** 文件名 */
name: string
/** 文件大小(字节) */
size: number
/** 文件 MIME 类型 */
type: string
/** 上传状态 */
status: 'ready' | 'uploading' | 'success' | 'error' | 'canceled'
/** 上传进度,取值范围 0-100 */
progress: number
/** 文件远程访问 URL 或自定义预览地址 */
url?: string
/** 原始 File 对象,用于上传请求、重试及本地预览生成 */
raw?: File
/** 错误信息 */
error?: UploadError
/** 当前已重试次数 */
retryCount?: number
/** 上传中止控制器 */
abortController?: AbortController
}Sourcepackages/ui/src/components/upload/Upload.vue | ||
@file-error | [file: UploadFile, error: UploadError] | Emitted when the upload callback reports an error, the upload Promise rejects, or retries are exhausted. Validation failures call onError without emitting this event. |
DetailsDeclared type[file: UploadFile, error: UploadError] Referenced types UploadError Type definition — UploadErrorexport interface UploadError {
/** 错误消息 */
message: string
/** 错误代码 */
code?: string
/** HTTP 状态码 */
status?: number
}UploadFile Type definition — UploadFileexport interface UploadFile {
/** 文件唯一标识符 */
id: string
/** 文件名 */
name: string
/** 文件大小(字节) */
size: number
/** 文件 MIME 类型 */
type: string
/** 上传状态 */
status: 'ready' | 'uploading' | 'success' | 'error' | 'canceled'
/** 上传进度,取值范围 0-100 */
progress: number
/** 文件远程访问 URL 或自定义预览地址 */
url?: string
/** 原始 File 对象,用于上传请求、重试及本地预览生成 */
raw?: File
/** 错误信息 */
error?: UploadError
/** 当前已重试次数 */
retryCount?: number
/** 上传中止控制器 */
abortController?: AbortController
}Sourcepackages/ui/src/components/upload/Upload.vue | ||
| Name | Signature or type | Description |
|---|---|---|
#trigger | { selectFiles: (files: FileList | File[]) => Promise<void>; limit: number | undefined; multiple: boolean; accept: string | undefined; drag: boolean; } | Replaces the file-selection trigger area. Its scope provides selectFiles, limit, multiple, accept, and drag for custom controls. |
DetailsDeclared type{ selectFiles: (files: FileList | File[]) => Promise<void>; limit: number | undefined; multiple: boolean; accept: string | undefined; drag: boolean; }Sourcepackages/ui/src/components/upload/Upload.vue | ||
#file-list | { files: { id: string; name: string; size: number; type: string; status: "success" | "error" | "ready" | "uploading" | "canceled"; progress: number; url?: string | undefined; raw?: { readonly lastModified: number; readonly name: string; readonly webkitRelativePath: string; readonly size: number; readonly type: string; arrayBuffer: () => Promise<ArrayBuffer>; bytes: () => Promise<Uint8Array<ArrayBuffer>>; slice: (start?: number | undefined, end?: number | undefined, contentType?: string | undefined) => Blob; stream: () => ReadableStream<Uint8Array<ArrayBuffer>>; text: () => Promise<string>; } | undefined; error?: { message: string; code?: string | undefined; status?: number | undefined; } | undefined; retryCount?: number | undefined; abortController?: { readonly signal: { readonly aborted: boolean; onabort: ((this: AbortSignal, ev: Event) => any) | null; readonly reason: any; throwIfAborted: () => void; addEventListener: { <K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | AddEventListenerOptions | undefined): void; (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions | undefined): void; }; removeEventListener: { <K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | EventListenerOptions | undefined): void; (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions | undefined): void; }; dispatchEvent: (event: Event) => boolean; }; abort: (reason?: any) => void; } | undefined; }[]; listType: "text" | "picture" | "picture-card"; remove: (file: UploadFile) => Promise<void>; retry: (file: UploadFile) => Promise<void>; } | Replaces the file list. Its scope provides the current files, listType, and remove(file) and retry(file) actions. |
DetailsDeclared type{ files: { id: string; name: string; size: number; type: string; status: "success" | "error" | "ready" | "uploading" | "canceled"; progress: number; url?: string | undefined; raw?: { readonly lastModified: number; readonly name: string; readonly webkitRelativePath: string; readonly size: number; readonly type: string; arrayBuffer: () => Promise<ArrayBuffer>; bytes: () => Promise<Uint8Array<ArrayBuffer>>; slice: (start?: number | undefined, end?: number | undefined, contentType?: string | undefined) => Blob; stream: () => ReadableStream<Uint8Array<ArrayBuffer>>; text: () => Promise<string>; } | undefined; error?: { message: string; code?: string | undefined; status?: number | undefined; } | undefined; retryCount?: number | undefined; abortController?: { readonly signal: { readonly aborted: boolean; onabort: ((this: AbortSignal, ev: Event) => any) | null; readonly reason: any; throwIfAborted: () => void; addEventListener: { <K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | AddEventListenerOptions | undefined): void; (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions | undefined): void; }; removeEventListener: { <K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | EventListenerOptions | undefined): void; (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions | undefined): void; }; dispatchEvent: (event: Event) => boolean; }; abort: (reason?: any) => void; } | undefined; }[]; listType: "text" | "picture" | "picture-card"; remove: (file: UploadFile) => Promise<void>; retry: (file: UploadFile) => Promise<void>; }Referenced types UploadFile Type definition — UploadFileexport interface UploadFile {
/** 文件唯一标识符 */
id: string
/** 文件名 */
name: string
/** 文件大小(字节) */
size: number
/** 文件 MIME 类型 */
type: string
/** 上传状态 */
status: 'ready' | 'uploading' | 'success' | 'error' | 'canceled'
/** 上传进度,取值范围 0-100 */
progress: number
/** 文件远程访问 URL 或自定义预览地址 */
url?: string
/** 原始 File 对象,用于上传请求、重试及本地预览生成 */
raw?: File
/** 错误信息 */
error?: UploadError
/** 当前已重试次数 */
retryCount?: number
/** 上传中止控制器 */
abortController?: AbortController
}Sourcepackages/ui/src/components/upload/Upload.vue | ||
#default | {} | Renders additional content after the trigger and file list; it has no scoped parameters. |
DetailsDeclared type{}Sourcepackages/ui/src/components/upload/Upload.vue | ||
| Name | Signature or type | Description |
|---|---|---|
handleFileSelect | (files: FileList | File[]) => Promise<void> | Programmatically submits a FileList or File array through the same validation, beforeUpload, list update, and optional auto-upload flow. |
DetailsDeclared type(files: FileList | File[]) => Promise<void> Sourcepackages/ui/src/components/upload/Upload.vue | ||
handleFileRemove | (file: UploadFile) => Promise<void> | Programmatically removes a file. The operation still honors beforeRemove and aborts an in-progress upload. |
DetailsDeclared type(file: UploadFile) => Promise<void> Referenced types UploadFile Type definition — UploadFileexport interface UploadFile {
/** 文件唯一标识符 */
id: string
/** 文件名 */
name: string
/** 文件大小(字节) */
size: number
/** 文件 MIME 类型 */
type: string
/** 上传状态 */
status: 'ready' | 'uploading' | 'success' | 'error' | 'canceled'
/** 上传进度,取值范围 0-100 */
progress: number
/** 文件远程访问 URL 或自定义预览地址 */
url?: string
/** 原始 File 对象,用于上传请求、重试及本地预览生成 */
raw?: File
/** 错误信息 */
error?: UploadError
/** 当前已重试次数 */
retryCount?: number
/** 上传中止控制器 */
abortController?: AbortController
}Sourcepackages/ui/src/components/upload/Upload.vue | ||
retryUpload | (file: UploadFile) => Promise<void> | Programmatically retries a file. Successful files are not retried, and the attempt is limited by maxRetries. |
DetailsDeclared type(file: UploadFile) => Promise<void> Referenced types UploadFile Type definition — UploadFileexport interface UploadFile {
/** 文件唯一标识符 */
id: string
/** 文件名 */
name: string
/** 文件大小(字节) */
size: number
/** 文件 MIME 类型 */
type: string
/** 上传状态 */
status: 'ready' | 'uploading' | 'success' | 'error' | 'canceled'
/** 上传进度,取值范围 0-100 */
progress: number
/** 文件远程访问 URL 或自定义预览地址 */
url?: string
/** 原始 File 对象,用于上传请求、重试及本地预览生成 */
raw?: File
/** 错误信息 */
error?: UploadError
/** 当前已重试次数 */
retryCount?: number
/** 上传中止控制器 */
abortController?: AbortController
}Sourcepackages/ui/src/components/upload/Upload.vue | ||
UploadFileItem
| Name | Type | Default | Description |
|---|---|---|---|
fileRequired | UploadFile | — | The file to render, including its upload status, progress, and error details. |
DetailsDeclared typeUploadFile Referenced types UploadFile Type definition — UploadFileexport interface UploadFile {
/** 文件唯一标识符 */
id: string
/** 文件名 */
name: string
/** 文件大小(字节) */
size: number
/** 文件 MIME 类型 */
type: string
/** 上传状态 */
status: 'ready' | 'uploading' | 'success' | 'error' | 'canceled'
/** 上传进度,取值范围 0-100 */
progress: number
/** 文件远程访问 URL 或自定义预览地址 */
url?: string
/** 原始 File 对象,用于上传请求、重试及本地预览生成 */
raw?: File
/** 错误信息 */
error?: UploadError
/** 当前已重试次数 */
retryCount?: number
/** 上传中止控制器 */
abortController?: AbortController
}Default value details
Sourcepackages/ui/src/components/upload/UploadFileItem.vue | |||
listType | "text" | "picture" | "picture-card" | undefined | "text" | Selects the text, picture, or picture-card layout for this file item. |
DetailsDeclared type"text" | "picture" | "picture-card" | undefined Literal values
Default value details
Sourcepackages/ui/src/components/upload/UploadFileItem.vue | |||
class | string | undefined | undefined | Custom CSS classes added to the file item root element. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/upload/UploadFileItem.vue | |||
| Name | Signature or type | Description |
|---|---|---|
@remove | [] | Emitted without a payload when the user activates the remove button; the parent handles removal. |
DetailsDeclared type[] Sourcepackages/ui/src/components/upload/UploadFileItem.vue | ||
@retry | [] | Emitted without a payload only when the file is in error state and the user activates the retry button. |
DetailsDeclared type[] Sourcepackages/ui/src/components/upload/UploadFileItem.vue | ||
UploadFileList
| Name | Type | Default | Description |
|---|---|---|---|
filesRequired | UploadFile[] | — | The file entries to render. The container is not rendered when the list is empty. |
DetailsDeclared typeUploadFile[] Referenced types UploadFile Type definition — UploadFileexport interface UploadFile {
/** 文件唯一标识符 */
id: string
/** 文件名 */
name: string
/** 文件大小(字节) */
size: number
/** 文件 MIME 类型 */
type: string
/** 上传状态 */
status: 'ready' | 'uploading' | 'success' | 'error' | 'canceled'
/** 上传进度,取值范围 0-100 */
progress: number
/** 文件远程访问 URL 或自定义预览地址 */
url?: string
/** 原始 File 对象,用于上传请求、重试及本地预览生成 */
raw?: File
/** 错误信息 */
error?: UploadError
/** 当前已重试次数 */
retryCount?: number
/** 上传中止控制器 */
abortController?: AbortController
}Default value details
Sourcepackages/ui/src/components/upload/UploadFileList.vue | |||
listType | "text" | "picture" | "picture-card" | undefined | "text" | The text, picture, or picture-card layout applied to each file item. |
DetailsDeclared type"text" | "picture" | "picture-card" | undefined Literal values
Default value details
Sourcepackages/ui/src/components/upload/UploadFileList.vue | |||
class | string | undefined | undefined | Custom CSS classes added to the file list container. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/upload/UploadFileList.vue | |||
| Name | Signature or type | Description |
|---|---|---|
@remove | [file: UploadFile] | Forwards the corresponding UploadFile when a child item emits remove. |
DetailsDeclared type[file: UploadFile] Referenced types UploadFile Type definition — UploadFileexport interface UploadFile {
/** 文件唯一标识符 */
id: string
/** 文件名 */
name: string
/** 文件大小(字节) */
size: number
/** 文件 MIME 类型 */
type: string
/** 上传状态 */
status: 'ready' | 'uploading' | 'success' | 'error' | 'canceled'
/** 上传进度,取值范围 0-100 */
progress: number
/** 文件远程访问 URL 或自定义预览地址 */
url?: string
/** 原始 File 对象,用于上传请求、重试及本地预览生成 */
raw?: File
/** 错误信息 */
error?: UploadError
/** 当前已重试次数 */
retryCount?: number
/** 上传中止控制器 */
abortController?: AbortController
}Sourcepackages/ui/src/components/upload/UploadFileList.vue | ||
@retry | [file: UploadFile] | Forwards the corresponding UploadFile when a child item emits retry. |
DetailsDeclared type[file: UploadFile] Referenced types UploadFile Type definition — UploadFileexport interface UploadFile {
/** 文件唯一标识符 */
id: string
/** 文件名 */
name: string
/** 文件大小(字节) */
size: number
/** 文件 MIME 类型 */
type: string
/** 上传状态 */
status: 'ready' | 'uploading' | 'success' | 'error' | 'canceled'
/** 上传进度,取值范围 0-100 */
progress: number
/** 文件远程访问 URL 或自定义预览地址 */
url?: string
/** 原始 File 对象,用于上传请求、重试及本地预览生成 */
raw?: File
/** 错误信息 */
error?: UploadError
/** 当前已重试次数 */
retryCount?: number
/** 上传中止控制器 */
abortController?: AbortController
}Sourcepackages/ui/src/components/upload/UploadFileList.vue | ||
UploadTrigger
| Name | Type | Default | Description |
|---|---|---|---|
drag | boolean | undefined | true | Whether to handle file-drop events. When disabled, drops are ignored and the dragging state is cleared. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/upload/UploadTrigger.vue | |||
disabled | boolean | undefined | false | Disables file selection and dropping, and removes the trigger area from the keyboard tab order. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/upload/UploadTrigger.vue | |||
accept | string | undefined | undefined | The accept type hint passed to the hidden native file input. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/upload/UploadTrigger.vue | |||
multiple | boolean | undefined | true | The multiple-selection setting passed to the native input. When false, both browsing and dropping keep only the first file. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/upload/UploadTrigger.vue | |||
class | string | undefined | undefined | Custom CSS classes added to the focusable trigger area. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/upload/UploadTrigger.vue | |||
| Name | Signature or type | Description |
|---|---|---|
@select | [files: File[], source: "browse" | "drop"] | Emitted with a non-empty file array after browsing or dropping, along with the browse or drop source. The array contains at most one file when multiple is false. |
DetailsDeclared type[files: File[], source: "browse" | "drop"] Literal values
Sourcepackages/ui/src/components/upload/UploadTrigger.vue | ||
| Name | Signature or type | Description |
|---|---|---|
#default | { isDragging: boolean; triggerFileInput: () => void; } | Replaces the entire trigger area. Its scope provides the live isDragging state and triggerFileInput() to open the file picker programmatically. |
DetailsDeclared type{ isDragging: boolean; triggerFileInput: () => void; }Sourcepackages/ui/src/components/upload/UploadTrigger.vue | ||
#text | {} | Replaces the main prompt inside the built-in trigger area and is used when the default slot is absent. Without this slot, the source currently renders a hardcoded Chinese prompt meaning “Click or drop files here to upload”; this text is not locale-aware. |
DetailsDeclared type{}Sourcepackages/ui/src/components/upload/UploadTrigger.vue | ||
#hint | {} | Replaces the helper text below the main prompt. The area is empty when this slot is not provided. |
DetailsDeclared type{}Sourcepackages/ui/src/components/upload/UploadTrigger.vue | ||
Types
UploadFile
interface UploadFile {
id: string
name: string
size: number
type: string
status: 'ready' | 'uploading' | 'success' | 'error' | 'canceled'
progress: number
url?: string
raw?: File
error?: UploadError
retryCount?: number
abortController?: AbortController
}UploadError
interface UploadError {
message: string
code?: string
status?: number
}UploadRequestOptions
interface UploadRequestOptions {
file: File
signal: AbortSignal
onProgress: (percent: number) => void
onSuccess: (response: unknown) => void
onError: (error: UploadError) => void
}Accessibility
- Keyboard: Trigger area is focusable and activatable with
Enter/Space - ARIA Attributes: Hidden file input is properly labeled
- Screen Readers: File status and progress are announced