Select选择器 - 图1

Select 选择器

下拉选择器。

何时使用

  • 弹出一个下拉菜单给用户选择操作,用于代替原生的选择器,或者需要一个更优雅的多选器时。
  • 当选项少时(少于 5 项),建议直接将选项平铺,使用 Radio 是更好的选择。

代码演示

Select选择器 - 图2

Select选择器 - 图3

Select选择器 - 图4

基本使用

基本使用。

  1. <template>
  2. <a-select
  3. v-model:value="value1"
  4. style="width: 120px"
  5. @focus="focus"
  6. ref="select"
  7. @change="handleChange"
  8. >
  9. <a-select-option value="jack">Jack</a-select-option>
  10. <a-select-option value="lucy">Lucy</a-select-option>
  11. <a-select-option value="disabled" disabled>Disabled</a-select-option>
  12. <a-select-option value="Yiminghe">yiminghe</a-select-option>
  13. </a-select>
  14. <a-select v-model:value="value2" style="width: 120px" disabled>
  15. <a-select-option value="lucy">Lucy</a-select-option>
  16. </a-select>
  17. <a-select v-model:value="value3" style="width: 120px" loading>
  18. <a-select-option value="lucy">Lucy</a-select-option>
  19. </a-select>
  20. </template>
  21. <script lang="ts">
  22. import { defineComponent, ref } from 'vue';
  23. export default defineComponent({
  24. setup() {
  25. const focus = () => {
  26. console.log('focus');
  27. };
  28. const handleChange = (value: string) => {
  29. console.log(`selected ${value}`);
  30. };
  31. return {
  32. focus,
  33. handleChange,
  34. value1: ref('lucy'),
  35. value2: ref('lucy'),
  36. value3: ref('lucy'),
  37. };
  38. },
  39. });
  40. </script>

Select选择器 - 图5

标签

tags select,随意输入的内容(scroll the menu)

  1. <template>
  2. <a-select
  3. v-model:value="value"
  4. mode="tags"
  5. style="width: 100%"
  6. placeholder="Tags Mode"
  7. @change="handleChange"
  8. >
  9. <a-select-option v-for="i in 25" :key="(i + 9).toString(36) + i">
  10. {{ (i + 9).toString(36) + i }}
  11. </a-select-option>
  12. </a-select>
  13. </template>
  14. <script lang="ts">
  15. import { defineComponent, ref } from 'vue';
  16. export default defineComponent({
  17. setup() {
  18. const handleChange = (value: string) => {
  19. console.log(`selected ${value}`);
  20. };
  21. return {
  22. value: ref([]),
  23. handleChange,
  24. };
  25. },
  26. });
  27. </script>

Select选择器 - 图6

获得选项的文本

默认情况下 onChange 里只能拿到 value,如果需要拿到选中的节点文本 label,可以使用 labelInValue 属性。 选中项的 label 会被包装到 value 中传递给 onChange 等函数,此时 value 是一个对象。

  1. <template>
  2. <a-select label-in-value v-model:value="value" style="width: 120px" @change="handleChange">
  3. <a-select-option value="jack">Jack (100)</a-select-option>
  4. <a-select-option value="lucy">Lucy (101)</a-select-option>
  5. </a-select>
  6. </template>
  7. <script lang="ts">
  8. import { defineComponent, ref } from 'vue';
  9. interface Value {
  10. key?: string;
  11. label?: string;
  12. }
  13. export default defineComponent({
  14. setup() {
  15. const handleChange = (value: Value) => {
  16. console.log(value); // { key: "lucy", label: "Lucy (101)" }
  17. };
  18. return {
  19. value: ref<Value>({ key: 'lucy' }),
  20. handleChange,
  21. };
  22. },
  23. });
  24. </script>

Select选择器 - 图7

Select选择器 - 图8

联动

省市联动是典型的例子。 推荐使用 Cascader 组件。

  1. <template>
  2. <a-select v-model:value="province" style="width: 120px">
  3. <a-select-option v-for="pro in provinceData" :key="pro">
  4. {{ pro }}
  5. </a-select-option>
  6. </a-select>
  7. <a-select v-model:value="secondCity" style="width: 120px">
  8. <a-select-option v-for="city in cities" :key="city">
  9. {{ city }}
  10. </a-select-option>
  11. </a-select>
  12. </template>
  13. <script lang="ts">
  14. const provinceData = ['Zhejiang', 'Jiangsu'];
  15. const cityData: Record<string, string[]> = {
  16. Zhejiang: ['Hangzhou', 'Ningbo', 'Wenzhou'],
  17. Jiangsu: ['Nanjing', 'Suzhou', 'Zhenjiang'],
  18. };
  19. import { defineComponent, reactive, toRefs, computed, watch } from 'vue';
  20. export default defineComponent({
  21. setup() {
  22. const province = provinceData[0];
  23. const state = reactive({
  24. province,
  25. provinceData,
  26. cityData,
  27. secondCity: cityData[province][0],
  28. });
  29. const cities = computed(() => {
  30. return cityData[state.province];
  31. });
  32. watch(
  33. () => state.province,
  34. val => {
  35. state.secondCity = state.cityData[val][0];
  36. },
  37. );
  38. return {
  39. ...toRefs(state),
  40. cities,
  41. };
  42. },
  43. });
  44. </script>

Select选择器 - 图9

搜索框

搜索和远程数据结合。

  1. <template>
  2. <a-select
  3. show-search
  4. v-model:value="value"
  5. placeholder="input search text"
  6. style="width: 200px"
  7. :default-active-first-option="false"
  8. :show-arrow="false"
  9. :filter-option="false"
  10. :not-found-content="null"
  11. @search="handleSearch"
  12. @change="handleChange"
  13. >
  14. <a-select-option v-for="d in data" :key="d.value">
  15. {{ d.text }}
  16. </a-select-option>
  17. </a-select>
  18. </template>
  19. <script lang="ts">
  20. import jsonp from 'fetch-jsonp';
  21. import querystring from 'querystring';
  22. import { defineComponent, ref } from 'vue';
  23. let timeout: any;
  24. let currentValue = '';
  25. function fetch(value: string, callback: any) {
  26. if (timeout) {
  27. clearTimeout(timeout);
  28. timeout = null;
  29. }
  30. currentValue = value;
  31. function fake() {
  32. const str = querystring.encode({
  33. code: 'utf-8',
  34. q: value,
  35. });
  36. jsonp(`https://suggest.taobao.com/sug?${str}`)
  37. .then(response => response.json())
  38. .then(d => {
  39. if (currentValue === value) {
  40. const result = d.result;
  41. const data: any[] = [];
  42. result.forEach((r: any) => {
  43. data.push({
  44. value: r[0],
  45. text: r[0],
  46. });
  47. });
  48. callback(data);
  49. }
  50. });
  51. }
  52. timeout = setTimeout(fake, 300);
  53. }
  54. export default defineComponent({
  55. setup() {
  56. const data = ref<any[]>([]);
  57. const value = ref();
  58. const handleSearch = (val: string) => {
  59. fetch(val, (d: any[]) => (data.value = d));
  60. };
  61. const handleChange = (val: string) => {
  62. console.log(val);
  63. value.value = val;
  64. fetch(val, (d: any[]) => (data.value = d));
  65. };
  66. return {
  67. handleSearch,
  68. handleChange,
  69. data,
  70. value,
  71. };
  72. },
  73. });
  74. </script>

Select选择器 - 图10

搜索用户

一个带有远程搜索,节流控制,请求时序控制,加载状态的多选示例。

  1. <template>
  2. <a-select
  3. mode="multiple"
  4. label-in-value
  5. v-model:value="value"
  6. placeholder="Select users"
  7. style="width: 100%"
  8. :filter-option="false"
  9. :not-found-content="fetching ? undefined : null"
  10. @search="fetchUser"
  11. >
  12. <template v-if="fetching" #notFoundContent>
  13. <a-spin size="small" />
  14. </template>
  15. <a-select-option v-for="d in data" :key="d.value">
  16. {{ d.text }}
  17. </a-select-option>
  18. </a-select>
  19. </template>
  20. <script>
  21. import { defineComponent, reactive, toRefs, watch } from 'vue';
  22. import { debounce } from 'lodash-es';
  23. export default defineComponent({
  24. setup() {
  25. let lastFetchId = 0;
  26. const state = reactive({
  27. data: [],
  28. value: [],
  29. fetching: false,
  30. });
  31. const fetchUser = debounce(value => {
  32. console.log('fetching user', value);
  33. lastFetchId += 1;
  34. const fetchId = lastFetchId;
  35. state.data = [];
  36. state.fetching = true;
  37. fetch('https://randomuser.me/api/?results=5')
  38. .then(response => response.json())
  39. .then(body => {
  40. if (fetchId !== lastFetchId) {
  41. // for fetch callback order
  42. return;
  43. }
  44. const data = body.results.map(user => ({
  45. text: `${user.name.first} ${user.name.last}`,
  46. value: user.login.username,
  47. }));
  48. state.data = data;
  49. state.fetching = false;
  50. });
  51. }, 800);
  52. watch(state.value, () => {
  53. state.data = [];
  54. state.fetching = false;
  55. });
  56. return {
  57. ...toRefs(state),
  58. fetchUser,
  59. };
  60. },
  61. });
  62. </script>

Select选择器 - 图11

隐藏已选择选项

隐藏下拉列表中已选择的选项。

  1. <template>
  2. <a-select
  3. mode="multiple"
  4. placeholder="Inserted are removed"
  5. v-model:value="selectedItems"
  6. style="width: 100%"
  7. >
  8. <a-select-option v-for="item in filteredOptions" :key="item" :value="item">
  9. {{ item }}
  10. </a-select-option>
  11. </a-select>
  12. </template>
  13. <script lang="ts">
  14. import { computed, defineComponent, ref } from 'vue';
  15. const OPTIONS = ['Apples', 'Nails', 'Bananas', 'Helicopters'];
  16. export default defineComponent({
  17. setup() {
  18. const selectedItems = ref<string[]>([]);
  19. const filteredOptions = computed(() => OPTIONS.filter(o => !selectedItems.value.includes(o)));
  20. return {
  21. selectedItems,
  22. filteredOptions,
  23. };
  24. },
  25. });
  26. </script>

Select选择器 - 图12

定制回填内容

使用 optionLabelProp 指定回填到选择框的 Option 属性。

  1. <template>
  2. <a-select
  3. v-model:value="value"
  4. mode="multiple"
  5. style="width: 100%"
  6. placeholder="select one country"
  7. option-label-prop="label"
  8. >
  9. <a-select-option value="china" label="China">
  10. <span role="img" aria-label="China">🇨🇳</span>
  11. China (中国)
  12. </a-select-option>
  13. <a-select-option value="usa" label="USA">
  14. <span role="img" aria-label="USA">🇺🇸</span>
  15. USA (美国)
  16. </a-select-option>
  17. <a-select-option value="japan" label="Japan">
  18. <span role="img" aria-label="Japan">🇯🇵</span>
  19. Japan (日本)
  20. </a-select-option>
  21. <a-select-option value="korea" label="Korea">
  22. <span role="img" aria-label="Korea">🇰🇷</span>
  23. Korea (韩国)
  24. </a-select-option>
  25. </a-select>
  26. </template>
  27. <script lang="ts">
  28. import { defineComponent, ref, watch } from 'vue';
  29. export default defineComponent({
  30. setup() {
  31. const value = ref(['china']);
  32. watch(value, val => {
  33. console.log(`selected:`, val);
  34. });
  35. return {
  36. value,
  37. };
  38. },
  39. });
  40. </script>

Select选择器 - 图13

Select选择器 - 图14

Select选择器 - 图15

Select选择器 - 图16

三种大小

三种大小的选择框,当 size 分别为 largesmall 时,输入框高度为 40px24px ,默认高度为 32px

  1. <template>
  2. <a-radio-group v-model:value="size">
  3. <a-radio-button value="large">Large</a-radio-button>
  4. <a-radio-button value="default">Default</a-radio-button>
  5. <a-radio-button value="small">Small</a-radio-button>
  6. </a-radio-group>
  7. <br />
  8. <br />
  9. <a-select :size="size" v-model:value="value1" style="width: 200px">
  10. <a-select-option v-for="i in 25" :key="(i + 9).toString(36) + i">
  11. {{ (i + 9).toString(36) + i }}
  12. </a-select-option>
  13. </a-select>
  14. <br />
  15. <a-select
  16. mode="multiple"
  17. :size="size"
  18. placeholder="Please select"
  19. v-model:value="value2"
  20. style="width: 200px"
  21. @popupScroll="popupScroll"
  22. >
  23. <a-select-option v-for="i in 25" :key="(i + 9).toString(36) + i">
  24. {{ (i + 9).toString(36) + i }}
  25. </a-select-option>
  26. </a-select>
  27. <br />
  28. <a-select
  29. mode="tags"
  30. :size="size"
  31. placeholder="Please select"
  32. v-model:value="value3"
  33. style="width: 200px"
  34. >
  35. <a-select-option v-for="i in 25" :key="(i + 9).toString(36) + i">
  36. {{ (i + 9).toString(36) + i }}
  37. </a-select-option>
  38. </a-select>
  39. </template>
  40. <script lang="ts">
  41. import { defineComponent, ref } from 'vue';
  42. export default defineComponent({
  43. setup() {
  44. const popupScroll = () => {
  45. console.log('popupScroll');
  46. };
  47. return {
  48. popupScroll,
  49. size: ref('default'),
  50. value1: ref('a1'),
  51. value2: ref(['a1', 'b2']),
  52. value3: ref(['a1', 'b2']),
  53. };
  54. },
  55. });
  56. </script>

Select选择器 - 图17

自动分词

试下复制 露西,杰克 到输入框里。只在 tags 和 multiple 模式下可用。

  1. <template>
  2. <a-select
  3. v-model:value="value"
  4. mode="tags"
  5. style="width: 100%"
  6. :token-separators="[',']"
  7. @change="handleChange"
  8. >
  9. <a-select-option v-for="i in 25" :key="(i + 9).toString(36) + i">
  10. {{ (i + 9).toString(36) + i }}
  11. </a-select-option>
  12. </a-select>
  13. </template>
  14. <script lang="ts">
  15. import { defineComponent, ref } from 'vue';
  16. export default defineComponent({
  17. setup() {
  18. const handleChange = (value: string) => {
  19. console.log(`selected ${value}`);
  20. };
  21. return {
  22. handleChange,
  23. value: ref<string[]>([]),
  24. };
  25. },
  26. });
  27. </script>

Select选择器 - 图18

多选

多选,从已有条目中选择(scroll the menu)

  1. <template>
  2. <a-select
  3. mode="multiple"
  4. v-model:value="value"
  5. style="width: 100%"
  6. placeholder="Please select"
  7. @change="handleChange"
  8. >
  9. <a-select-option v-for="i in 25" :key="(i + 9).toString(36) + i">
  10. {{ (i + 9).toString(36) + i }}
  11. </a-select-option>
  12. </a-select>
  13. </template>
  14. <script lang="ts">
  15. import { defineComponent, ref } from 'vue';
  16. export default defineComponent({
  17. setup() {
  18. const handleChange = (value: string[]) => {
  19. console.log(`selected ${value}`);
  20. };
  21. return {
  22. handleChange,
  23. value: ref(['a1', 'b2']),
  24. };
  25. },
  26. });
  27. </script>

Select选择器 - 图19

分组

OptGroup 进行选项分组。

  1. <template>
  2. <a-select v-model:value="value" style="width: 200px" @change="handleChange">
  3. <a-select-opt-group>
  4. <template #label>
  5. <span>
  6. <user-outlined />
  7. Manager
  8. </span>
  9. </template>
  10. <a-select-option value="jack">Jack</a-select-option>
  11. <a-select-option value="lucy">Lucy</a-select-option>
  12. </a-select-opt-group>
  13. <a-select-opt-group label="Engineer">
  14. <a-select-option value="Yiminghe">yiminghe</a-select-option>
  15. <a-select-option value="Yiminghe1">yiminghe1</a-select-option>
  16. </a-select-opt-group>
  17. </a-select>
  18. </template>
  19. <script lang="ts">
  20. import { defineComponent, ref } from 'vue';
  21. import { UserOutlined } from '@ant-design/icons-vue';
  22. export default defineComponent({
  23. setup() {
  24. const handleChange = (value: string) => {
  25. console.log(`selected ${value}`);
  26. };
  27. return {
  28. value: ref(['lucy']),
  29. handleChange,
  30. };
  31. },
  32. components: {
  33. UserOutlined,
  34. },
  35. });
  36. </script>

Select选择器 - 图20

带搜索框

展开后可对选项进行搜索。

  1. <template>
  2. <a-select
  3. v-model:value="value"
  4. show-search
  5. placeholder="Select a person"
  6. option-filter-prop="children"
  7. style="width: 200px"
  8. :filter-option="filterOption"
  9. @focus="handleFocus"
  10. @blur="handleBlur"
  11. @change="handleChange"
  12. >
  13. <a-select-option value="jack">Jack</a-select-option>
  14. <a-select-option value="lucy">Lucy</a-select-option>
  15. <a-select-option value="tom">Tom</a-select-option>
  16. </a-select>
  17. </template>
  18. <script lang="ts">
  19. import { defineComponent, ref } from 'vue';
  20. export default defineComponent({
  21. setup() {
  22. const handleChange = (value: string) => {
  23. console.log(`selected ${value}`);
  24. };
  25. const handleBlur = () => {
  26. console.log('blur');
  27. };
  28. const handleFocus = () => {
  29. console.log('focus');
  30. };
  31. const filterOption = (input: string, option: any) => {
  32. return option.props.value.toLowerCase().indexOf(input.toLowerCase()) >= 0;
  33. };
  34. return {
  35. value: ref<string | undefined>(undefined),
  36. filterOption,
  37. handleBlur,
  38. handleFocus,
  39. handleChange,
  40. };
  41. },
  42. });
  43. </script>

Select选择器 - 图21

Select选择器 - 图22

后缀图标

基本使用。

  1. <template>
  2. <a-select v-model:value="value1" style="width: 120px" @change="handleChange">
  3. <template #suffixIcon><smile-outlined /></template>
  4. <a-select-option value="jack">Jack</a-select-option>
  5. <a-select-option value="lucy">Lucy</a-select-option>
  6. <a-select-option value="disabled" disabled>Disabled</a-select-option>
  7. <a-select-option value="Yiminghe">yiminghe</a-select-option>
  8. </a-select>
  9. <a-select v-model:value="value2" style="width: 120px" disabled>
  10. <template #suffixIcon><meh-outlined /></template>
  11. <a-select-option value="lucy">Lucy</a-select-option>
  12. </a-select>
  13. </template>
  14. <script lang="ts">
  15. import { SmileOutlined, MehOutlined } from '@ant-design/icons-vue';
  16. import { defineComponent, ref } from 'vue';
  17. export default defineComponent({
  18. setup() {
  19. const handleChange = (value: string) => {
  20. console.log(`selected ${value}`);
  21. };
  22. return {
  23. handleChange,
  24. value1: ref('lucy'),
  25. value2: ref('lucy'),
  26. };
  27. },
  28. components: {
  29. SmileOutlined,
  30. MehOutlined,
  31. },
  32. });
  33. </script>

Select选择器 - 图23

扩展菜单

使用 dropdownRender 对下拉菜单进行自由扩展。

  1. <template>
  2. <a-select v-model:value="value" style="width: 120px">
  3. <template #dropdownRender="{ menuNode: menu }">
  4. <v-nodes :vnodes="menu" />
  5. <a-divider style="margin: 4px 0" />
  6. <div
  7. style="padding: 4px 8px; cursor: pointer"
  8. @mousedown="e => e.preventDefault()"
  9. @click="addItem"
  10. >
  11. <plus-outlined />
  12. Add item
  13. </div>
  14. </template>
  15. <a-select-option v-for="item in items" :key="item" :value="item">
  16. {{ item }}
  17. </a-select-option>
  18. </a-select>
  19. </template>
  20. <script lang="ts">
  21. import { PlusOutlined } from '@ant-design/icons-vue';
  22. import { defineComponent, ref } from 'vue';
  23. let index = 0;
  24. export default defineComponent({
  25. setup() {
  26. const items = ref(['jack', 'lucy']);
  27. const value = ref('lucy');
  28. const addItem = () => {
  29. console.log('addItem');
  30. items.value.push(`New item ${index++}`);
  31. };
  32. return {
  33. items,
  34. value,
  35. addItem,
  36. };
  37. },
  38. components: {
  39. PlusOutlined,
  40. VNodes: (_, { attrs }) => {
  41. return attrs.vnodes;
  42. },
  43. },
  44. });
  45. </script>

10000 Items

Select选择器 - 图24

大数据

Select 使用了虚拟滚动技术,因而获得了比 1.x 更好的性能

  1. <template>
  2. <h2>{{ options.length }} Items</h2>
  3. <a-select
  4. v-model:value="value"
  5. mode="multiple"
  6. style="width: 100%"
  7. placeholder="Please select"
  8. :options="options"
  9. />
  10. </template>
  11. <script lang="ts">
  12. import { defineComponent, reactive } from 'vue';
  13. const options: { value: string; disabled: boolean }[] = [];
  14. for (let i = 0; i < 10000; i++) {
  15. const value = `${i.toString(36)}${i}`;
  16. options.push({
  17. value,
  18. disabled: i === 10,
  19. });
  20. }
  21. export default defineComponent({
  22. setup() {
  23. const state = reactive({
  24. options,
  25. value: ['a10', 'c12'],
  26. });
  27. return state;
  28. },
  29. });
  30. </script>

API

  1. <a-select>
  2. <a-select-option value="lucy">lucy</a-select-option>
  3. </a-select>

Select props

参数说明类型默认值
allowClear支持清除booleanfalse
autoClearSearchValue是否在选中项后清空搜索框,只在 modemultipletags 时有效。booleantrue
autofocus默认获取焦点booleanfalse
defaultActiveFirstOption是否默认高亮第一个选项。booleantrue
disabled是否禁用booleanfalse
dropdownClassName下拉菜单的 className 属性string-
dropdownMatchSelectWidth下拉菜单和选择器同宽booleantrue
dropdownRender自定义下拉框内容({menuNode: VNode, props}) => VNode | v-slot-
dropdownStyle下拉菜单的 style 属性object-
dropdownMenuStyledropdown 菜单自定义样式object-
filterOption是否根据输入项进行筛选。当其为一个函数时,会接收 inputValue option 两个参数,当 option 符合筛选条件时,应返回 true,反之则返回 falseboolean or function(inputValue, option)true
firstActiveValue默认高亮的选项string|string[]-
getPopupContainer菜单渲染父节点。默认渲染到 body 上,如果你遇到菜单滚动定位问题,试试修改为滚动的区域,并相对其定位。Function(triggerNode)() => document.body
labelInValue是否把每个选项的 label 包装到 value 中,会把 Select 的 value 类型从 string 变为 {key: string, label: vNodes} 的格式booleanfalse
maxTagCount最多显示多少个 tagnumber-
maxTagPlaceholder隐藏 tag 时显示的内容slot/function(omittedValues)-
maxTagTextLength最大显示的 tag 文本长度number-
mode设置 Select 的模式为多选或标签‘default’ | ‘multiple’ | ‘tags’ | ‘combobox’-
notFoundContent当下拉列表为空时显示的内容string|slot‘Not Found’
optionFilterProp搜索时过滤对应的 option 属性,不支持 childrenstringvalue
optionLabelProp回填到选择框的 Option 的属性值,默认是 Option 的子元素。比如在子元素需要高亮效果时,此值可以设为 valuestringchildren (combobox 模式下为 value
placeholder选择框默认文字string|slot-
showSearch使单选模式可搜索booleanfalse
showArrow是否显示下拉小箭头booleantrue
size选择框大小,可选 large smallstringdefault
suffixIcon自定义的选择框后缀图标VNode | slot-
removeIcon自定义的多选框清除图标VNode | slot-
clearIcon自定义的多选框清空图标VNode | slot-
menuItemSelectedIcon自定义当前选中的条目图标VNode | slot-
tokenSeparators在 tags 和 multiple 模式下自动分词的分隔符string[]
value(v-model)指定当前选中的条目string|string[]|number|number[]-
optionsoptions 数据,如果设置则不需要手动构造 selectOption 节点array<{value, label, [disabled, key, title]}>[]
defaultOpen是否默认展开下拉菜单boolean-
open是否展开下拉菜单boolean-

注意,如果发现下拉菜单跟随页面滚动,或者需要在其他弹层中触发 Select,请尝试使用 getPopupContainer={triggerNode => triggerNode.parentNode} 将下拉弹层渲染节点固定在触发器的父元素中。

事件

事件名称说明回调参数
blur失去焦点的时回调function
change选中 option,或 input 的 value 变化(combobox 模式下)时,调用此函数function(value, option:Option/Array<Option>)
deselect取消选中时调用,参数为选中项的 value (或 key) 值,仅在 multiple 或 tags 模式下生效function(value,option:Option)
focus获得焦点时回调function
inputKeydown键盘按下时回调function
mouseenter鼠标移入时回调function
mouseleave鼠标移出时回调function
popupScroll下拉列表滚动时的回调function
search文本框值变化时回调function(value: string)
select被选中时调用,参数为选中项的 value (或 key) 值function(value, option:Option)
dropdownVisibleChange展开下拉菜单的回调function(open)

Select Methods

名称说明
blur()取消焦点
focus()获取焦点

Option props

参数说明类型默认值
disabled是否禁用booleanfalse
key和 value 含义一致。如果 Vue 需要你设置此项,此项值与 value 的值相同,然后可以省略 value 设置string
title选中该 Option 后,Select 的 titlestring-
value默认根据此属性值进行筛选string|number-
classOption 器类名string-

OptGroup props

参数说明类型默认值
keystring-
label组名string||function(h)|slot

FAQ

点击 dropdownRender 里的内容浮层关闭怎么办?

看下 dropdownRender 例子 里的说明。