Skip to content

Switch 开关

表示两种相互对立的状态间的切换,多用于触发「开/关」。

基础用法

自定义大小

文字描述

显示自定义图标

扩展的 value 类型

禁用状态

加载状态

阻止切换

API

Props

参数说明类型默认值
v-model开关选中状态anyfalse
size开关按钮的尺寸,默认单位为 pxnumber | string26px
loading是否为加载状态booleanfalse
disabled是否为禁用状态booleanfalse
active-value打开时对应的值anytrue
inactive-value关闭时对应的值anyfalse
inline-prompt控制文本是否显示在点内booleanfalse
active-text打开时的文字描述string-
inactive-icon关闭时的文字描述string-
active-icon打开时所显示图标,设置此项会忽略 active-textstring | Component-
inactive-icon关闭时所显示图标,设置此项会忽略 inactive-textstring | Component-

Events

事件名说明回调参数
change开关状态切换时触发value: any
click点击时触发event: MouseEvent

Slots

名称说明参数
node自定义按钮的内容-
background自定义开关的背景内容-

类型定义

组件导出以下类型定义:

ts
import type { SwitchProps } from 'ryxon'

主题定制

样式变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 组件

名称默认值描述
--r-switch-size26px-
--r-switch-widthcalc(2em + 4px)-
--r-switch-heightcalc(1em + 4px)-
--r-switch-node-size1em-
--r-switch-node-backgroundvar(--r-white)-
--r-switch-node-shadow0 3px 1px 0 rgba(0, 0, 0, 0.05)-
--r-switch-backgroundrgba(120, 120, 128, 0.16)-
--r-switch-on-backgroundvar(--r-primary-color)-
--r-switch-durationvar(--r-duration-base)-
--r-switch-disabled-opacityvar(--r-disabled-opacity)-

Released under the MIT License.