Skip to content

Checkbox 多选框

在一组备选项中进行多选。

基础用法

单选

表示两种状态之间的切换

vue




多选

适用于多个勾选框绑定到同一个数组的情景,通过是否勾选来表示这一组选项中选中的项。

vue






禁用状态

多选框不可用状态。

设置 disabled 属性即可。

vue




中间状态

indeterminate 属性用以表示 checkbox 的不确定状态,一般用于实现全选的效果

注意

indeterminate 属性和 modelValue 的值是不关联的,且该属性只用来展示样式所用,一般用于表示全选的状态.
全选的中间状态是只要选中一个就会出现中间态,全部选中中间态失效。中间态即为示例中 横杠 的样式

vue




状态

点击时改变 modelValue,indeterminate 要自己控制,一共有如下四个状态,避免出现都为True的情况

选中取消(空白)中间态无效(填满)
intermediatefalsefalsetruetrue
modelValuetruefalsefalsetrue

Checkbox Props

参数类型是否必传说明默认值
modelValuestring/number/boolean/array选中的值-
trueValuenumber/string/boolean选中的值true
falseValuenumber/string/boolean未选中的值false
valuenumber/stringmodelValue 是数组时,选中时的值,如果不提供,将会降级使用 trueValueundefined
disabledboolean禁用false
indeterminatenumber/string/boolean中间状态,独立于 modelValue,需要用户手动控制false

Checkbox 事件

事件名称说明参数
change当绑定值变化时触发的事件改变后的值

Checkbox 插槽

插槽名称说明
default自定义默认内容