Skip to content

Select ​

简易介绍 ​

select选择器组件,用于用户从下拉列表中选择一个或多个选项。
实现选择器有两种标签: <MYSelect />或者<MYSelect></MYSelect><MYOption />或者<MYOption></MYOption>

基础用法 ​

使用v-model绑定选中的值。

代码演示
请选择水果
展开代码

禁用状态 ​

禁用整个选择器 ​

使用disabled属性可以禁用选择器。

代码演示
禁用状态
展开代码

禁用某个选项 ​

使用disabled属性可以禁用单个选项。

代码演示
禁用某个选项
展开代码

自定义尺寸 ​

使用width和height属性可以自定义选择器的宽度和高度。

代码演示
宽300px高50px
展开代码

自定义颜色 ​

使用backgroundColor、hoverbackgroundColor和borderColor属性可以自定义选择器的颜色。

代码演示
自定义颜色
展开代码

API 参考 ​

Select Props ​

参数说明类型可选值默认值
modelValue绑定值string | number—''
placeholder占位文本string—'请选择'
disabled是否禁用boolean—false
width宽度string | number—'260px'
height高度string | number—'40px'
backgroundColor背景色string—''
hoverbackgroundColor悬停背景色string—''
borderColor边框颜色string—''
autoScrollbar自动滚动条boolean—true

Option Props ​

参数说明类型可选值默认值
value选项值string | number——
label选项标签string—''
disabled是否禁用boolean—false

类型定义 ​

typescript
interface SelectProps {
  modelValue?: string | number;
  placeholder?: string;
  disabled?: boolean;
  width?: string | number;
  height?: string | number;
  backgroundColor?: string;
  hoverbackgroundColor?: string;
  borderColor?: string;
  autoScrollbar?: boolean;
}

interface OptionProps {
  value: string | number;
  label?: string;
  disabled?: boolean;
}

基于 MIT 协议