Autocomplete 自動補全
LhAutocomplete 自動補全輸入框。
基礎用法
基礎用法
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhAutocomplete } from '@lh-ui/vue3'
const value = ref('')
const options = [
{ label: 'Vue' },
{ label: 'Vue Router' },
{ label: 'Vite' },
{ label: 'Vitest' },
]
const t1 = {
placeholder: '輸入框架名稱',
}
</script>
<template>
<LhAutocomplete v-model="value" :options="options" :placeholder="t1.placeholder" />
</template>vue
<script>
import { LhAutocomplete } from '@lh-ui/vue3'
export default {
components: { LhAutocomplete },
data() {
return {
value: '',
options: [
{ label: 'Vue' },
{ label: 'Vue Router' },
{ label: 'Vite' },
{ label: 'Vitest' },
],
t1: {
placeholder: '輸入框架名稱',
},
}
},
}
</script>
<template>
<LhAutocomplete v-model="value" :options="options" :placeholder="t1.placeholder" />
</template>帶提交值的選項
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhAutocomplete } from '@lh-ui/vue3'
const value2 = ref('')
const members = [
{ label: '張三', value: 'alice' },
{ label: '李四', value: 'bob' },
]
const t2 = {
placeholder2: '輸入成員名字',
}
</script>
<template>
<LhAutocomplete v-model="value2" :options="members" :placeholder="t2.placeholder2" />
</template>vue
<script>
import { LhAutocomplete } from '@lh-ui/vue3'
export default {
components: { LhAutocomplete },
data() {
return {
value2: '',
members: [
{ label: '張三', value: 'alice' },
{ label: '李四', value: 'bob' },
],
t2: {
placeholder2: '輸入成員名字',
},
}
},
}
</script>
<template>
<LhAutocomplete v-model="value2" :options="members" :placeholder="t2.placeholder2" />
</template>Autocomplete API
屬性
| 屬性名 | 說明 | 類型 | 預設值 |
|---|---|---|---|
| modelValue | 輸入值 | string | '' |
| options | 建議選項 | LhAutocompleteOption[] | [] |
| caseSensitive | 大小寫敏感 | boolean | false |
| trim | 去除首尾空白後匹配 | boolean | true |
| placeholder | 佔位提示 | string | '' |
| disabled | 停用 | boolean | false |
| openOnFocus | 聚焦時是否展開 | boolean | true |
| ariaLabel | 無障礙名稱 | string | — |
| sx | 快速版面配置屬性 | LhSxProps | — |
事件
| 屬性名 | 說明 | 類型 |
|---|---|---|
| update:modelValue | 輸入值變化時觸發 | (value: string) |
| change | 輸入值變化時觸發 | (value: string) |
| select | 選中建議項時觸發 | (value: string | number, option: LhAutocompleteOption) |
插槽
| 屬性名 | 說明 |
|---|---|
| empty | 無匹配時的空態內容 |
無障礙
- 遵循 APG combobox 模式

