Skip to content

Select 选择器 ​

从下拉列表中选择一项或多项。

基础用法 ​

使用 v-model 绑定选中项的 value,通过 options 提供选项。

查看代码收起代码
vue
<script setup lang="ts">
import { ZSelect } from '@codex-proxy/ui'
import { ref } from 'vue'

const group = ref<string>()
const groups = [
  { value: 'production', label: '生产环境' },
  { value: 'testing', label: '测试环境' },
  { value: 'development', label: '开发环境' },
  { value: 'paused', label: '暂停使用', disabled: true },
]
</script>

<template>
  <ZSelect v-model="group" :options="groups" aria-label="账号分组" class="w-60 max-w-full" />
</template>

筛选选项 ​

设置 filterable 后,可直接在选择框内输入关键词,按名称或说明筛选选项。用方向键定位,按回车选中。

查看代码收起代码
vue
<script setup lang="ts">
import { ZSelect } from '@codex-proxy/ui'
import { ref } from 'vue'

const group = ref('production')
const groups = [
  { value: 'production', label: '生产环境' },
  { value: 'testing', label: '测试环境' },
  { value: 'development', label: '开发环境' },
  { value: 'paused', label: '暂停使用', disabled: true },
]
</script>

<template>
  <ZSelect v-model="group" :options="groups" aria-label="账号分组" class="w-60 max-w-full" filterable />
</template>

多选 ​

设置 multiple 可选择多项,绑定值为数组。

查看代码收起代码
vue
<script setup lang="ts">
import { ZSelect } from '@codex-proxy/ui'
import { ref } from 'vue'

const group = ref(['production', 'testing'])
const groups = [
  { value: 'production', label: '生产环境' },
  { value: 'testing', label: '测试环境' },
  { value: 'development', label: '开发环境' },
  { value: 'paused', label: '暂停使用', disabled: true },
]
</script>

<template>
  <ZSelect v-model="group" :options="groups" aria-label="账号分组" class="w-60 max-w-full" multiple />
</template>

折叠标签 ​

设置 collapse-tags 折叠已选项,搭配 collapse-tags-tooltip 可查看隐藏标签。

查看代码收起代码
vue
<script setup lang="ts">
import { ZSelect } from '@codex-proxy/ui'
import { ref } from 'vue'

const group = ref(['production', 'testing', 'development'])
const groups = [
  { value: 'production', label: '生产环境' },
  { value: 'testing', label: '测试环境' },
  { value: 'development', label: '开发环境' },
  { value: 'paused', label: '暂停使用', disabled: true },
]
</script>

<template>
  <ZSelect v-model="group" :options="groups" aria-label="账号分组" class="w-60 max-w-full" multiple collapse-tags collapse-tags-tooltip />
</template>

Select API ​

属性 ​

属性说明类型默认值
validate-event随控件事件触发表单校验booleantrue
multiple-limit多选可选数量上限,0 表示不限number0
no-match-text搜索无匹配时的文案string语言包
loading-text加载时的文案string语言包
v-modelValue 为 string 或 number;单选空值 undefined,多选空值 [],0 是有效值Value | undefined 或 Value[]必填
optionslabel、value;可选 description、disabledSelectOption<Value>[]必填
size组件尺寸'small' | 'default' | 'large''default'
multiple开启多选booleanfalse
disabled / loading / filterable / clearable / remote禁用、加载、搜索、清空、外部筛选booleanfalse
remote-method远程搜索回调,接收最后一次输入的关键词(query: string) => void—
debounce远程搜索的防抖时间(毫秒),0 表示立即调用number300
placeholder / empty-text占位和空状态string'请选择' / '暂无选项'
collapse-tags / collapse-tags-tooltip折叠标签与溢出提示booleanfalse
max-collapse-tags至少显示一个标签number1

remote 模式下,query-change 随输入立即发出,可用于取消旧请求。remote-method 在停止输入后调用,关闭菜单会取消等待中的回调。分页由 end-reached 触发。通过 ZFormItem 或 aria-label 为控件命名

事件 ​

事件参数说明
update:modelValue / change当前模型值模型变化 / 用户选择、移除或清空
clear无清空选择
remove-tagValue用户移除一个标签
visible-changeboolean菜单显隐变化
query-changestring搜索输入完成
popup-scroll{ scrollTop, scrollLeft }下拉浮层的滚动坐标
end-reachedtop / bottom / left / right滚动到达的边界方向
focus / blurFocusEvent触发控件焦点变化

远程分页时监听 end-reached,方向为 bottom、有下一页且请求空闲时才加载。将新选项追加到原列表会保留滚动位置与键盘焦点,loading 用于替换整份结果时的加载提示。

插槽 ​

  • option({ option, index, selected, disabled }):自定义选项内容
  • empty({ search }):无匹配选项

实例 ​

focus()、blur()、clear()、open()、close()