Skip to content

AutoComplete 自动补全 ​

输入框带候选提示,支持本地过滤与远程取数。

基础用法 ​

本地数据源会按输入内容自动过滤。

vue
<template>
  <KbAutoComplete v-model="value" :options="['Vue', 'React', 'Svelte']" />
</template>

远程取数 ​

fetch-suggestions 返回候选数组(同步或 Promise),返回空数组表示无结果。

vue
<template>
  <KbAutoComplete :fetch-suggestions="search" placeholder="搜索用户" />
</template>

<script setup>
const search = async (query) => {
  const res = await fetch(`/api/users?q=${query}`)
  return res.json()
}
</script>

API ​

Props ​

属性类型默认值说明
modelValuestring''输入值
optionsstring[] | { value, label, disabled }[][]候选数据源
placeholderstring语言包 common.placeholder占位文案
disabledbooleanfalse禁用
clearablebooleanfalse可清空
filterbooleantrue是否本地过滤
fetchSuggestions(query) => Option[] | Promise<Option[]>—远程取数
size'small' | 'medium' | 'large'ConfigProvider尺寸

事件 ​

事件参数说明
update:modelValuestring输入变化
selectOption选中候选项
changestring值变化

键盘 ​

按键行为
↑ / ↓移动高亮项
Enter选中高亮项
Esc关闭面板