forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.vue
54 lines (47 loc) · 1.09 KB
/
search.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<docs>
---
order: 9
title:
zh-CN: 带搜索框
en-US: Select with search field
---
## zh-CN
展开后可对选项进行搜索。
## en-US
Search the options while expanded.
</docs>
<template>
<a-select
v-model:value="value"
show-search
placeholder="Select a person"
style="width: 200px"
:options="options"
:filter-option="filterOption"
@focus="handleFocus"
@blur="handleBlur"
@change="handleChange"
></a-select>
</template>
<script lang="ts" setup>
import type { SelectProps } from 'ant-design-vue';
import { ref } from 'vue';
const options = ref<SelectProps['options']>([
{ value: 'jack', label: 'Jack' },
{ value: 'lucy', label: 'Lucy' },
{ value: 'tom', label: 'Tom' },
]);
const handleChange = (value: string) => {
console.log(`selected ${value}`);
};
const handleBlur = () => {
console.log('blur');
};
const handleFocus = () => {
console.log('focus');
};
const filterOption = (input: string, option: any) => {
return option.value.toLowerCase().indexOf(input.toLowerCase()) >= 0;
};
const value = ref<string | undefined>(undefined);
</script>