Skip to content

Select 选择器

下拉选择组件。

基础用法

适用广泛的基础单选。

选中值:
vue
<template>
  <x-select v-model="value" :options="options" placeholder="请选择" />
</template>

<script setup>
import { ref } from 'vue'

const value = ref('')
const options = [
  { value: 'option1', label: '选项一' },
  { value: 'option2', label: '选项二' },
  { value: 'option3', label: '选项三' }
]
</script>

禁用状态

vue
<template>
  <x-select disabled :options="options" placeholder="禁用状态" />
</template>

可清空

vue
<template>
  <x-select v-model="value" :options="options" clearable placeholder="可清空" />
</template>

多选

设置 type="multiple" 启用多选模式。

选中值: []
vue
<template>
  <x-select v-model="value" :options="options" type="multiple" placeholder="请选择" />
</template>

<script setup>
import { ref } from 'vue'
const value = ref([])
</script>

多选限制数量

使用 multiple-limit 限制多选数量。

vue
<template>
  <x-select v-model="value" :options="options" type="multiple" :multiple-limit="3" placeholder="最多选择3个" />
</template>

级联选择

设置 type="cascader" 启用级联选择模式,适用于省市区、分类等层级数据。

选中值: []
vue
<template>
  <x-select v-model="value" :options="options" type="cascader" placeholder="请选择地区" />
</template>

<script setup>
import { ref } from 'vue'

const value = ref([])
const options = [
  {
    value: 'zhejiang',
    label: '浙江省',
    children: [
      {
        value: 'hangzhou',
        label: '杭州市',
        children: [
          { value: 'xihu', label: '西湖区' },
          { value: 'jianggan', label: '江干区' }
        ]
      }
    ]
  }
]
</script>

可搜索

设置 filterable 启用搜索功能。

vue
<template>
  <x-select v-model="value" :options="options" filterable placeholder="请输入关键字搜索" />
</template>

不同尺寸

vue
<template>
  <x-select size="large" :options="options" placeholder="大型" />
  <x-select :options="options" placeholder="默认" />
  <x-select size="small" :options="options" placeholder="小型" />
</template>

API

Props

属性说明类型默认值
modelValue绑定值string | number | (string | number)[]
options选项数据SelectOption[][]
type选择类型'single' | 'multiple' | 'cascader''single'
placeholder占位文本string'请选择'
disabled是否禁用booleanfalse
clearable是否可清空booleanfalse
filterable是否可搜索booleanfalse
filterMethod自定义搜索方法(query: string, option: SelectOption) => boolean
size输入框尺寸'large' | 'default' | 'small''default'
multipleLimit多选限制数量number0
collapseTags是否折叠标签booleantrue
maxCollapseTags折叠标签最大数量number1
separator级联分隔符string' / '
valueKey值字段名string'value'
labelKey标签字段名string'label'
childrenKey子节点字段名string'children'
noDataText无数据提示string'暂无数据'
noMatchText无匹配提示string'无匹配数据'

SelectOption 数据结构

字段说明类型默认值
value选项值string | number
label选项标签string
disabled是否禁用booleanfalse
children子选项(级联时使用)SelectOption[]

Events

事件名说明回调参数
update:modelValue值改变时触发(value: string | number | (string | number)[])
change值改变时触发(value: string | number | (string | number)[])
clear清空时触发
focus获得焦点时触发(event: FocusEvent)
blur失去焦点时触发(event: FocusEvent)
visible-change下拉框显示状态改变时触发(visible: boolean)
remove-tag多选模式下移除标签时触发(tag: string | number)

基于 MIT 许可发布