Skip to content

Switch 开关 ​

何时使用 ​

表示两种互斥状态之间的切换时使用。

基础用法 ​

文字描述 ​

自定义取值 ​

当前值:on

禁用 ​

API ​

Props ​

属性说明类型默认值必填
modelValue / v-model当前值;与 activeValue / inactiveValue 比较判断开关状态boolean | string | numberfalse否
activeValue打开时写入的值boolean | string | numbertrue否
inactiveValue关闭时写入的值boolean | string | numberfalse否
activeText打开侧文案string—否
inactiveText关闭侧文案string—否
disabled禁用;可继承 Formbooleanfalse否

Events ​

事件名说明回调参数
update:modelValuev-model 更新(value: boolean | string | number) => void
change切换完成,并联动 FormItem(value: boolean | string | number) => void

Slots ​

无内容插槽;文案通过 activeText / inactiveText 配置。

无障碍 ​

根节点为 button[role=switch],带 aria-checked。

Token ​

变量说明
--dan-color-primary打开态轨道颜色
--dan-duration-fast滑块过渡