FileInput (文件选择)

样式化的文件选择按钮(v-model File | File[]),触发器可自定义。

基础用法

Basic.vue

多文件

可一次选择多个文件

  • 尚未选择文件
Multiple.vue

自定义触发器

CustomTrigger.vue

禁用与错误

请选择一个文件

States.vue

属性

属性类型默认值说明
acceptstring""Native `accept` filter for the picker, e.g. `"image/*"` or `".pdf,.zip"`. A filter, not a guarantee — validate on the server too.
classNamestring""Extra classes, merged after the component's own classes so yours wins the conflict — KunUI's `rounded-kun-*` / `shadow-kun-*` scales included.
descriptionstring""Helper text below the trigger (hidden when `error` is set). Canonical name.
disabledbooleanfalseBlocks the picker and dims the trigger.
errorstring""Error message below the trigger. Setting it also paints the invalid state and hides `description`.
filesFile[][]The picked files in `multiple` mode, two-way bound with `v-model:files`. Always an array; empty when nothing is picked.
fullWidthbooleanfalseStretch the trigger to the container's full width.
hintstring""Helper text below the field.
maxSizenumberLargest accepted file, in BYTES. A file over it is rejected and reported through `error`.
modelValueFile | nullnullThe picked file, two-way bound with `v-model`. `null` when nothing is picked; stays `null` in `multiple` mode — read `v-model:files` there.
multiplebooleanfalseAllow picking more than one file.
showFileNamebooleantruePrint the picked file name (or the count, when `multiple`) next to the trigger.
triggerColorKunUIColor"primary"Semantic colour of the trigger button.
triggerIconstring"lucide:upload"Icon name on the trigger button. Must be one of KunUI's bundled icons — an unbundled name renders nothing.
triggerSizeKunUISize"md"Size of the trigger button, on the shared form-control scale.
triggerTextstring"选择文件"Label on the trigger button.
triggerVariantKunUIVariant"flat"Visual style of the trigger button (see KunButton `variant`).

事件

事件回调参数说明
changepicked: File[]The files that passed `accept` and `maxSize`.
errorPickmessage: stringA human-readable reason a picked file was rejected.
update:filesvalue: File[]
update:modelValuevalue: File | null

插槽

插槽作用域
#default{ pick: () => void; disabled: boolean; fileName: string | null; }