Select选择器·续1
<template> <a-select v-model:value="value" mode="multiple" style="width: 100%" placeholder="select one country" option-label-prop="label" > <a-select-option value="china" label="China"> <span role="img" aria-label="China">🇨🇳</span> China (中国) </a-select-option> <a-select-option value="usa" label="USA"> <span role="img" aria-label="USA">🇺🇸</span> USA (美国) </a-select-option> <a-select-option value="japan" label="Japan"> <span role="img" aria-label="Japan">🇯🇵</span> Japan (日本) </a-select-option> <a-select-option value="korea" label="Korea"> <span role="img" aria-label="Korea">🇰🇷</span> Korea (韩国) </a-select-option> </a-select></template><script lang="ts">import { defineComponent, ref, watch } from 'vue';export default defineComponent({ setup() { const value = ref(['china']); watch(value, val => { console.log(`selected:`, val); }); return { value, }; },});</script>
三种大小
三种大小的选择框,当 size 分别为 large 和 small 时,输入框高度为 40px 和 24px ,默认高度为 32px。
<template> <a-radio-group v-model:value="size"> <a-radio-button value="large">Large</a-radio-button> <a-radio-button value="default">Default</a-radio-button> <a-radio-button value="small">Small</a-radio-button> </a-radio-group> <br /> <br /> <a-select :size="size" v-model:value="value1" style="width: 200px"> <a-select-option v-for="i in 25" :key="(i + 9).toString(36) + i"> {{ (i + 9).toString(36) + i }} </a-select-option> </a-select> <br /> <a-select mode="multiple" :size="size" placeholder="Please select" v-model:value="value2" style="width: 200px" @popupScroll="popupScroll" > <a-select-option v-for="i in 25" :key="(i + 9).toString(36) + i"> {{ (i + 9).toString(36) + i }} </a-select-option> </a-select> <br /> <a-select mode="tags" :size="size" placeholder="Please select" v-model:value="value3" style="width: 200px" > <a-select-option v-for="i in 25" :key="(i + 9).toString(36) + i"> {{ (i + 9).toString(36) + i }} </a-select-option> </a-select></template><script lang="ts">import { defineComponent, ref } from 'vue';export default defineComponent({ setup() { const popupScroll = () => { console.log('popupScroll'); }; return { popupScroll, size: ref('default'), value1: ref('a1'), value2: ref(['a1', 'b2']), value3: ref(['a1', 'b2']), }; },});</script>
自动分词
试下复制 露西,杰克 到输入框里。只在 tags 和 multiple 模式下可用。
<template> <a-select v-model:value="value" mode="tags" style="width: 100%" :token-separators="[',']" @change="handleChange" > <a-select-option v-for="i in 25" :key="(i + 9).toString(36) + i"> {{ (i + 9).toString(36) + i }} </a-select-option> </a-select></template><script lang="ts">import { defineComponent, ref } from 'vue';export default defineComponent({ setup() { const handleChange = (value: string) => { console.log(`selected ${value}`); }; return { handleChange, value: ref<string[]>([]), }; },});</script>
多选
多选,从已有条目中选择(scroll the menu)
<template> <a-select mode="multiple" v-model:value="value" style="width: 100%" placeholder="Please select" @change="handleChange" > <a-select-option v-for="i in 25" :key="(i + 9).toString(36) + i"> {{ (i + 9).toString(36) + i }} </a-select-option> </a-select></template><script lang="ts">import { defineComponent, ref } from 'vue';export default defineComponent({ setup() { const handleChange = (value: string[]) => { console.log(`selected ${value}`); }; return { handleChange, value: ref(['a1', 'b2']), }; },});</script>
分组
用 OptGroup 进行选项分组。
<template> <a-select v-model:value="value" style="width: 200px" @change="handleChange"> <a-select-opt-group> <template #label> <span> <user-outlined /> Manager </span> </template> <a-select-option value="jack">Jack</a-select-option> <a-select-option value="lucy">Lucy</a-select-option> </a-select-opt-group> <a-select-opt-group label="Engineer"> <a-select-option value="Yiminghe">yiminghe</a-select-option> <a-select-option value="Yiminghe1">yiminghe1</a-select-option> </a-select-opt-group> </a-select></template><script lang="ts">import { defineComponent, ref } from 'vue';import { UserOutlined } from '@ant-design/icons-vue';export default defineComponent({ setup() { const handleChange = (value: string) => { console.log(`selected ${value}`); }; return { value: ref(['lucy']), handleChange, }; }, components: { UserOutlined, },});</script>
带搜索框
展开后可对选项进行搜索。
<template> <a-select v-model:value="value" show-search placeholder="Select a person" option-filter-prop="children" style="width: 200px" :filter-option="filterOption" @focus="handleFocus" @blur="handleBlur" @change="handleChange" > <a-select-option value="jack">Jack</a-select-option> <a-select-option value="lucy">Lucy</a-select-option> <a-select-option value="tom">Tom</a-select-option> </a-select></template><script lang="ts">import { defineComponent, ref } from 'vue';export default defineComponent({ setup() { 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.props.value.toLowerCase().indexOf(input.toLowerCase()) >= 0; }; return { value: ref<string | undefined>(undefined), filterOption, handleBlur, handleFocus, handleChange, }; },});</script>
后缀图标
基本使用。
<template> <a-select v-model:value="value1" style="width: 120px" @change="handleChange"> <template #suffixIcon><smile-outlined /></template> <a-select-option value="jack">Jack</a-select-option> <a-select-option value="lucy">Lucy</a-select-option> <a-select-option value="disabled" disabled>Disabled</a-select-option> <a-select-option value="Yiminghe">yiminghe</a-select-option> </a-select> <a-select v-model:value="value2" style="width: 120px" disabled> <template #suffixIcon><meh-outlined /></template> <a-select-option value="lucy">Lucy</a-select-option> </a-select></template><script lang="ts">import { SmileOutlined, MehOutlined } from '@ant-design/icons-vue';import { defineComponent, ref } from 'vue';export default defineComponent({ setup() { const handleChange = (value: string) => { console.log(`selected ${value}`); }; return { handleChange, value1: ref('lucy'), value2: ref('lucy'), }; }, components: { SmileOutlined, MehOutlined, },});</script>
扩展菜单
使用 dropdownRender 对下拉菜单进行自由扩展。
<template> <a-select v-model:value="value" style="width: 120px"> <template #dropdownRender="{ menuNode: menu }"> <v-nodes :vnodes="menu" /> <a-divider style="margin: 4px 0" /> <div style="padding: 4px 8px; cursor: pointer" @mousedown="e => e.preventDefault()" @click="addItem" > <plus-outlined /> Add item </div> </template> <a-select-option v-for="item in items" :key="item" :value="item"> {{ item }} </a-select-option> </a-select></template><script lang="ts">import { PlusOutlined } from '@ant-design/icons-vue';import { defineComponent, ref } from 'vue';let index = 0;export default defineComponent({ setup() { const items = ref(['jack', 'lucy']); const value = ref('lucy'); const addItem = () => { console.log('addItem'); items.value.push(`New item ${index++}`); }; return { items, value, addItem, }; }, components: { PlusOutlined, VNodes: (_, { attrs }) => { return attrs.vnodes; }, },});</script>
10000 Items
大数据
