ant-design-vue/components/auto-complete/demo/options.vue

58 lines
1.1 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<docs>
---
order: 1
title:
zh-CN: 自定义选项
en-US: Customized
---
## zh-CN
3.0 以上版本可以传递 `v-slot:option` 来自定义 Option
## en-US
For 3.0+, You could pass `v-slot:option` to custom option.
</docs>
<template>
<a-auto-complete
v-model:value="value"
style="width: 200px"
placeholder="input here"
:options="options"
@search="handleSearch"
>
<template #option="{ value: val }">
{{ val.split('@')[0] }} @
<span style="font-weight: bold">{{ val.split('@')[1] }}</span>
</template>
</a-auto-complete>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue';
export default defineComponent({
setup() {
const value = ref('');
const options = ref<{ value: string }[]>([]);
const handleSearch = (val: string) => {
let res: { value: string }[];
if (!val || val.indexOf('@') >= 0) {
res = [];
} else {
res = ['gmail.com', '163.com', 'qq.com'].map(domain => ({ value: `${val}@${domain}` }));
}
options.value = res;
};
return {
value,
options,
handleSearch,
};
},
});
</script>