TUI

0.3.7
Select 下拉选择框
基础下拉选择框组件,支持单选、禁用、自定义内容等。
基础用法
默认 type 为 text,支持 v-model 双向绑定。
北京
示例代码
vue
<template>
  <TsSelect v-model="cityValue" :options="cityList" placeholder="请选择城市" @change="changeCity" />
</template>

<script setup lang="ts">
  const cityList = [
    { label: '北京', value: '北京' },
    { label: '上海', value: '上海' },
    { label: '广州', value: '广州' },
    { label: '深圳', value: '深圳' },
  ];
  const cityValue = ref('北京');

  const changeCity = (val: string) => {
    console.log('选中的城市:', val);
  }
</script>
一键清空
使用 clearable 属性即可得到一个可一键清空的选择器
北京
示例代码
vue
<template>
  <TsSelect v-model="cityValue" clearable :options="cityList" placeholder="请选择城市" @change="changeCity" />
</template>

<script setup lang="ts">
  import { ref } from 'vue';

  const cityList = [
    { label: '北京', value: '北京' },
    { label: '上海', value: '上海' },
    { label: '广州', value: '广州' },
    { label: '深圳', value: '深圳' },
  ];
  const cityValue = ref('北京');

  const changeCity = (val: string) => {
    console.log('选中的城市:', val);
  }
</script>
禁用状态
通过 disabled 属性控制组件是否可用。或者optionItem 的 disabled 属性。
广州
请选择城市
示例代码
vue
<template>
  <TsSelect v-model="disabledValue" :options="cityList" placeholder="禁用状态" disabled />
  <TsSelect v-model="disabledOptionValue" :options="cityDisabledList" placeholder="请选择城市" />
</template>

<script setup lang="ts">
  import { ref } from 'vue';

  const cityList = [
    { label: '北京', value: '北京' },
    { label: '上海', value: '上海' },
    { label: '广州', value: '广州' },
    { label: '深圳', value: '深圳' },
  ];

  const cityDisabledList = [
    { label: '北京', value: '北京' },
    { label: '上海', value: '上海' },
    { label: '广州', value: '广州', disabled: true },
    { label: '深圳', value: '深圳' },
    { label: '重庆', value: '重庆' },
  ];

  const disabledValue = ref('广州');
  const disabledOptionValue = ref('');

</script>
多选选项
通过 multiple 实现多选功能
北京
上海
示例代码
vue
<template>
  <TsSelect style="width: 200px" multiple v-model="multipleValue" :options="cityList" placeholder="请选择城市" />
</template>

<script setup lang="ts">
  import { ref } from 'vue';

  const cityList = [
    { label: '北京', value: '北京' },
    { label: '上海', value: '上海' },
    { label: '广州', value: '广州' },
    { label: '深圳', value: '深圳' },
  ];
  const cityValue = ref('北京');

  const changeCity = (val: string) => {
    console.log('选中的城市:', val);
  }
</script>
筛选选项
通过 filterable 来快速筛选label、value 的匹配项。
广州
示例代码
vue
<template>
  <TsSelect style="width: 200px" filterable v-model="disabledValue" :options="cityDisabledList" placeholder="请选择城市" />
</template>

<script setup lang="ts">
  import { ref } from 'vue';

  const cityList = [
    { label: '北京', value: '北京' },
    { label: '上海', value: '上海' },
    { label: '广州', value: '广州' },
    { label: '深圳', value: '深圳' },
  ];
  const cityValue = ref('北京');

  const changeCity = (val: string) => {
    console.log('选中的城市:', val);
  }
</script>
错误状态
通过 errorerrorText 展示错误提示。
请选择城市

该字段为必填项

示例代码
vue
<template>
  <TsSelect v-model="errorValue" :options="cityList" placeholder="请选择城市" error errorText="该字段为必填项" />
</template>

<script setup lang="ts">
  import { ref } from 'vue';

  const cityList = [
    { label: '北京', value: '北京' },
    { label: '上海', value: '上海' },
    { label: '广州', value: '广州' },
    { label: '深圳', value: '深圳' },
  ];
  const errorValue = ref('');
</script>
不同尺寸
通过 size 属性可设置下拉框尺寸,支持 small、medium、large、x-large 四种预设值。 若不传入 size ,则默认使用 medium 尺寸。。
小尺寸
默认尺寸
大尺寸
超大尺寸
示例代码
vue
<template>
  <TsSelect v-model="smallValue" :options="cityList" size="small" placeholder="小尺寸" />
  <TsSelect v-model="defaultValue" :options="cityList" size="medium" placeholder="默认尺寸" />
  <TsSelect v-model="largeValue" :options="cityList" size="large" placeholder="大尺寸" />
  <TsSelect v-model="xlargeValue" :options="cityList" size="x-large" placeholder="超大尺寸" />
</template>

<script setup lang="ts">
  import { ref } from 'vue';

  const cityList = [
    { label: '北京', value: '北京' },
    { label: '上海', value: '上海' },
    { label: '广州', value: '广州' },
    { label: '深圳', value: '深圳' },
  ];

  const smallValue = ref('');
  const defaultValue = ref('');
  const largeValue = ref('');
  const xlargeValue = ref('');
</script>
属性 Props
属性名
说明
类型
可选值
默认值
版本说明
v-model
绑定值
string | number
options
下拉数据列表
Array<SelectOptionItem>
[]
size
尺寸大小
string
small / medium / large
medium
multiple
是否多选
boolean
false
filterable
是否筛选
boolean
false
disabled
是否禁用
boolean
true / false
false
placeholder
占位符提示文本
string
0.3.6 变更为空字符串
required
是否必填
boolean
true / false
false
clearable
是否一键清除
boolean
false
error
是否显示错误状态
boolean
true / false
false
errorText
错误提示信息内容
string
errorFixed
错误提示是否固定占位
boolean
false
scrollIntoView
是否滚动到选中项
boolean
true / false
false
centerSelectedOnOpen
打开时选中项是否居中
boolean
true / false
true
directionFollow
下拉框是否跟随滚动调整方向
boolean
true / false
true
dropBorder
是否显示下拉框边框
boolean
true / false
true
事件 Events
事件名
说明
类型
change
值变化时触发
(value: string | number | boolean | null | undefined, options: SelectOptionItem[)=> void
clear
清空值时触发
(value: null)=> void
插槽 Slots
插槽名
说明
suffix-icon
下拉图标插槽
SelectOptionItem Props
属性名
说明
类型
可选值
默认值
label
选项展示文本
string
value
选项绑定值
string | number | boolean
disabled
该选项是否禁用
boolean
true / false
false