File Upload

在队列或附件工作区管理文件、预览、进度与重试操作。

适用场景

  • 当界面需要以下行为时使用 File Upload:在队列或附件工作区管理文件、预览、进度与重试操作。

安装

选择安装方式,用法示例将同步更新导入路径。

$ bunx --bun shadcn-vue@2.8.2 add https://orvui.efu.me/r/file-upload.json https://orvui.efu.me/r/attachment-upload.json

首次使用时,将安装的 src/components/orvui/styles.css 导入项目样式入口。

示例

Attachment Upload

attachment-upload.vue

管理混合附件,查看预览、进度、重试操作与图片详情。

Attachments:

  • launch-brief.pdfUpload failed31 MB
  • orange-flowers.jpg9.3 MB
  • 0:120:48

Upload Queue

upload-queue.vue

将选择或拖入的文件加入队列,并分别管理上传进度。

Upload package

1 of 3 files ready

  • brand-assets.zip

    ZIP · 18 MB

    Uploaded
  • release-cut.mov

    MOV · 80 MB

    Uploading
  • vendor-contract.pdf

    PDF · 2.7 MB · Connection lost

    Failed

状态与事件

需要由表单、路由或父组件管理时,绑定下列状态并接收对应更新。v-model 是属性与 update 事件的简写;值的类型应与 API 一致。

组件状态绑定
组件Vue 绑定更新事件
FileUploadv-modelFileUploadItem[]update:modelValue
AttachmentUploadv-modelAttachmentUploadItem[]update:modelValue

可选受控属性未传入时,按组件文档的默认行为工作;不要用固定的 false 或空值代替未传入。异步请求和持久化在应用中处理,再把结果传回组件。

API 参考

Attachment Upload

modelValue?
AttachmentUploadItem[]
—
value?
AttachmentUploadItem[]
—
defaultValue?
AttachmentUploadItem[]
() => []
playingId?
string
—
accept?
string
—
multiple?
boolean
true
maxFiles?
number
12
maxFileSize?
number
500 * 1024 * 1024
disabled?
boolean
false
title?
string
"Drag and drop or browse files"
description?
string
—
attachmentsLabel?
string
"Attachments"
className?
string
—
classNames?
AttachmentUploadClassNames
—
onRetry?
(item: AttachmentUploadItem) => void
—

事件

update:modelValue
[items: AttachmentUploadItem[]]
@update:modelValue
valueChange
[items: AttachmentUploadItem[]]
@valueChange
filesAdded
[items: AttachmentUploadItem[], files: File[]]
@filesAdded
filesRejected
[files: File[], reason: AttachmentRejectReason]
@filesRejected
remove
[item: AttachmentUploadItem]
@remove
retry
[item: AttachmentUploadItem]
@retry
audioToggle
[item: AttachmentUploadItem]
@audioToggle

Upload Queue

modelValue?
FileUploadItem[]
—
value?
FileUploadItem[]
—
defaultValue?
FileUploadItem[]
() => []
accept?
string
—
multiple?
boolean
true
maxFiles?
number
—
disabled?
boolean
false
variant?
"default" | "centered"
"default"
title?
string
"Drop files here"
description?
string
"Add files to the upload queue"
browseLabel?
string
"Browse"
className?
string
—
classNames?
FileUploadClassNames
—

事件

update:modelValue
[items: FileUploadItem[]]
@update:modelValue
valueChange
[items: FileUploadItem[]]
@valueChange
filesAdded
[items: FileUploadItem[], files: File[]]
@filesAdded
remove
[item: FileUploadItem]
@remove
retry
[item: FileUploadItem]
@retry
reject
[files: File[]]
@reject

无障碍

为交互控件提供明确的无障碍名称。保留文档中的键盘路径、可见焦点与减少动态效果状态;自定义插槽应继续保留所替代部件的语义。

常见问题

如何配置 File Upload?
通过 modelValue、value、defaultValue、accept、multiple、maxFiles、disabled、variant、title、description、browseLabel、className、classNames 配置 File Upload;API 表列出其类型与默认值。
如何连接到应用状态?
监听 update:modelValue、valueChange、filesAdded、remove、retry、reject,将组件连接到应用状态。
可以在服务端渲染吗?
可以在 Vue SSR 应用中正常渲染。服务端与客户端的初始 props 应保持一致;浏览器测量与交互资源在挂载后启动。

请留意

部分组件参考了开源作品,相关署名与独立许可请参阅 NOTICE。

更新于