Select选择器·续1

<​template>  <​a-sel​ect    v-model:value="value"    mode="multiple"    style="width: 100%"    placeholder="sel​ect one country"    option-label-prop="label"  >    <​a-sel​ect-option value="china" label="China">      <​span role="img" aria-label="China">🇨🇳<​/span>      China (中国)    <​/a-sel​ect-option>    <​a-sel​ect-option value="usa" label="USA">      <​span role="img" aria-label="USA">🇺🇸<​/span>      USA (美国)    <​/a-sel​ect-option>    <​a-sel​ect-option value="japan" label="Japan">      <​span role="img" aria-label="Japan">🇯🇵<​/span>      Japan (日本)    <​/a-sel​ect-option>    <​a-sel​ect-option value="korea" label="Korea">      <​span role="img" aria-label="Korea">🇰🇷<​/span>      Korea (韩国)    <​/a-sel​ect-option>  <​/a-sel​ect><​/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-sel​ect :size="size" v-model:value="value1" style="width: 200px">    <​a-sel​ect-option v-for="i in 25" :key="(i + 9).toString(36) + i">      {{ (i + 9).toString(36) + i }}    <​/a-sel​ect-option>  <​/a-sel​ect>  <​br />  <​a-sel​ect    mode="multiple"    :size="size"    placeholder="Please sel​ect"    v-model:value="value2"    style="width: 200px"    @popupScroll="popupScroll"  >    <​a-sel​ect-option v-for="i in 25" :key="(i + 9).toString(36) + i">      {{ (i + 9).toString(36) + i }}    <​/a-sel​ect-option>  <​/a-sel​ect>  <​br />  <​a-sel​ect    mode="tags"    :size="size"    placeholder="Please sel​ect"    v-model:value="value3"    style="width: 200px"  >    <​a-sel​ect-option v-for="i in 25" :key="(i + 9).toString(36) + i">      {{ (i + 9).toString(36) + i }}    <​/a-sel​ect-option>  <​/a-sel​ect><​/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-sel​ect    v-model:value="value"    mode="tags"    style="width: 100%"    :token-separators="[',']"    @change="handleChange"  >    <​a-sel​ect-option v-for="i in 25" :key="(i + 9).toString(36) + i">      {{ (i + 9).toString(36) + i }}    <​/a-sel​ect-option>  <​/a-sel​ect><​/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-sel​ect    mode="multiple"    v-model:value="value"    style="width: 100%"    placeholder="Please sel​ect"    @change="handleChange"  >    <​a-sel​ect-option v-for="i in 25" :key="(i + 9).toString(36) + i">      {{ (i + 9).toString(36) + i }}    <​/a-sel​ect-option>  <​/a-sel​ect><​/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-sel​ect v-model:value="value" style="width: 200px" @change="handleChange">    <​a-sel​ect-opt-group>      <​template #label>        <​span>          <​user-outlined />          Manager        <​/span>      <​/template>      <​a-sel​ect-option value="jack">Jack<​/a-sel​ect-option>      <​a-sel​ect-option value="lucy">Lucy<​/a-sel​ect-option>    <​/a-sel​ect-opt-group>    <​a-sel​ect-opt-group label="Engineer">      <​a-sel​ect-option value="Yiminghe">yiminghe<​/a-sel​ect-option>      <​a-sel​ect-option value="Yiminghe1">yiminghe1<​/a-sel​ect-option>    <​/a-sel​ect-opt-group>  <​/a-sel​ect><​/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-sel​ect    v-model:value="value"    show-search    placeholder="Sel​ect a person"    option-filter-prop="children"    style="width: 200px"    :filter-option="filterOption"    @focus="handleFocus"    @blur="handleBlur"    @change="handleChange"  >    <​a-sel​ect-option value="jack">Jack<​/a-sel​ect-option>    <​a-sel​ect-option value="lucy">Lucy<​/a-sel​ect-option>    <​a-sel​ect-option value="tom">Tom<​/a-sel​ect-option>  <​/a-sel​ect><​/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-sel​ect v-model:value="value1" style="width: 120px" @change="handleChange">    <​template #suffixIcon><​smile-outlined /><​/template>    <​a-sel​ect-option value="jack">Jack<​/a-sel​ect-option>    <​a-sel​ect-option value="lucy">Lucy<​/a-sel​ect-option>    <​a-sel​ect-option value="disabled" disabled>Disabled<​/a-sel​ect-option>    <​a-sel​ect-option value="Yiminghe">yiminghe<​/a-sel​ect-option>  <​/a-sel​ect>  <​a-sel​ect v-model:value="value2" style="width: 120px" disabled>    <​template #suffixIcon><​meh-outlined /><​/template>    <​a-sel​ect-option value="lucy">Lucy<​/a-sel​ect-option>  <​/a-sel​ect><​/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-sel​ect 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-sel​ect-option v-for="item in items" :key="item" :value="item">      {{ item }}    <​/a-sel​ect-option>  <​/a-sel​ect><​/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

大数据