Skip to content

Checkbox 复选框

复选框是一种允许用户从一组选项中选择多个选项的控件。它通常用于表单中,允许用户进行多项选择。

Checkbox 参数

Props

名称类型默认值描述
modelValueboolean | any[]-选中状态,可以是布尔值或数组
valuestring | number-复选框值,在组合使用时有效
typeComponentType'default'复选框类型
shape'check' | 'dot''check'复选框形状
sizeComponentSize'medium'复选框大小
disabledbooleanfalse是否禁用
labelstring-标签内容
indeterminatebooleanfalse是否为不确定状态

Slots

名称描述参数
default默认插槽,用于显示复选框标签-
box自定义复选框图标{ checked: boolean, indeterminate: boolean, disabled: boolean }

Events

名称描述参数
update:modelValue复选框值变化时触发(value: boolean | any[]) => void
change复选框值变化时触发(value: boolean | any[]) => void

CheckboxGroup 参数

Props

名称类型默认值描述
modelValue(string | number)[][]选中值数组
typeComponentType'default'复选框组类型
sizeComponentSize'medium'复选框组大小
disabledbooleanfalse是否禁用
directionDirection'horizontal'布局方向
gapstring | number0间距
allboolean | null-全选状态,true 为全选,false 为全不选,null 为部分选中

Slots

名称描述参数
default默认插槽,用于放置 Checkbox 组件-

Events

名称描述参数
update:modelValue选中值变化时触发(value: (string | number)[]) => void
change选中值变化时触发(value: (string | number)[]) => void
update:all全选状态变化时触发(value: boolean | null) => void

示例

基础用法

不同形状

不同尺寸

不同类型

禁用状态

不确定状态

复选框组

组尺寸和类型

组禁用

自定义内容

TypeScript

ts
// 基础颜色类型
export type ComponentType =
  | "default"
  | "primary"
  | "secondary"
  | "success"
  | "warning"
  | "error"
  | "info";

// 组件尺寸
export type ComponentSize = "small" | "medium" | "large";

// 方向
export type Direction = "horizontal" | "vertical";