Autocomplete (自动完成)

组合框:文本输入 + 过滤建议列表(v-model 字符串);支持 allowCustomValue 与手动过滤。

基础用法

Basic.vue

自定义值

值: —

CustomValue.vue

可清除

Clearable.vue

错误 / 禁用

请选择一个有效城市

ErrorDisabled.vue

颜色

Colors.vue

远程搜索(loading + debounce)

confirmed value:

RemoteSearch.vue

自定义选项(#option 插槽)

CustomOption.vue

属性

属性类型默认值说明
options *readonly KunAutocompleteOption[]
allowCustomValuebooleantrueAccept a value the user typed that is not in `options` (free text).
ariaLabelstring""
clearablebooleanfalse
colorKunUIColor"default"Focus-ring accent (the resting border/text stay neutral). Default 'default'.
darkBorderbooleantrueLegacy dark-mode border toggle.
debouncenumber0Debounce the `@search` emit by N ms; the input text still updates instantly (a responsive field). 0 (default) emits on every keystroke — set e.g. 300 for remote sources so you fetch once the user pauses, not per keypress.
descriptionstring""Helper text below the field (hidden when `error` is set).
disabledbooleanfalse
errorstring""
isInvalidbooleanfalse
labelstring""
loadingbooleanfalseAsync data source: show a loading spinner in the dropdown (instead of `noResultText`) while a remote `@search` request is in flight. Drive it from your fetch — set true when the request starts, false when the results land.
loadingTextstring"加载中…"Text under the loading spinner. Default '加载中…'.
manualFilterbooleanfalseSkip built-in label filtering — you control `options` from `@search` (remote/async suggestions). Default false (client-side filter).
modelValuestring""
namestring
noResultTextstring"无匹配项"
placeholderstring""
roundedKunUIRoundedCorner radius. When unset it follows the nearest KunUIConfigProvider's `rounded`. `full` means a pill, which is only defined for the single-line trigger — the floating panel falls back to `lg`, because `9999px` on an n-row panel is clamped by the browser to half its short side. Every other bucket applies to both.
sizeKunUISize"md"

事件

事件回调参数说明
searchquery: stringThe field text, debounced by `debounce`. One emit per committed word during IME composition, not one per romaji keystroke.
selectoption: KunAutocompleteOptionThe option the user committed by click or Enter. Free text accepted through `allowCustomValue` does not emit it.
update:modelValuevalue: string

插槽

插槽作用域
#option{ option: KunAutocompleteOption; index: number; active: boolean; selected: boolean; }