Skip to content

FileUpload

qxs-file-upload@qxs-bns/components 里的文件上传组件,适合后台附件上传、活动资料提交、压缩包分发这类需要拖拽上传、文件格式限制和上传成功回调的场景。

基础用法

loading
ts
import '@qxs-bns/components/file-upload'

如果你已经全量引入:

ts
import '@qxs-bns/components'

使用说明

loading
  • qxs-file-upload 默认通过 upload-success 回抛上传结果;为了迁移旧版 Vue 事件,也会同时派发 on-success
  • filesheadersdata 这类对象属性建议通过 DOM property 传入,Vue 模板里写成 .prop
  • 默认上传区尺寸与 qxs-image-upload 对齐;如果宿主需要更大的附件拖拽区,可以通过 widthheight 调整。
  • 组件内部已经包含拖拽和点击上传入口,不需要宿主再额外包一层按钮。

常见场景

loading

宿主接入示例

loading

API

属性

NameDescriptionTypeDefault
action上传地址string''
headers请求头。推荐通过 property 传入Record<string, string>undefined
data上传时附带的额外字段。推荐通过 property 传入Record<string, string | Blob>undefined
name文件字段名string'file'
size单文件大小限制,单位 MBnumber20
width上传区域宽度,单位 pxnumber160
height上传区域高度,单位 pxnumber90
max最大上传数量number3
accept允许扩展名列表,逗号分隔string'zip,rar'
files初始文件列表。推荐通过 property 传入Array<{ name: string, url?: string, file?: File }>[]
notip是否隐藏默认提示区booleanfalse
ext兼容旧版的扩展名数组入口,优先级高于 acceptstring[][]

事件

NameDescription
upload-success上传成功后触发,detail 包含 responsefilefilesitems
on-success兼容旧版 Vue 监听写法的别名事件
files-change文件列表变化时触发,detail.items 为当前列表

插槽

NameDescription
tip自定义提示文案。未传时使用默认说明

CSS Parts

PartDescription
container外层容器
control拖拽 / 点击上传区域
icon上传图标
text上传文案
list文件列表
item单个文件项
remove删除按钮
status校验提示或上传结果提示
tip默认提示区

常见问题

为什么推荐用 property 传 filesheadersdata

因为这些值都是对象,不适合序列化成 HTML attribute。
在 Vue 里写 .prop,在 React / 原生 HTML 里直接给 DOM 实例赋值,都会更稳定。

upload-successon-success 有什么区别?

upload-success 是 WC 版主事件名。
on-success 只是兼容旧 Vue 写法的别名,新的宿主接入建议统一用 upload-success

相关文档

FileUpload has loaded