Skip to content
🌏 Translated with the assistance of DeepSeek and ChatGPT

Switch Component

This component is called Switch. It sounds just like a certain game console - makes me want to play so bad......

Basic Usage

Pass modelValue to enter controlled mode. If not passed or set to undefined, it will be in uncontrolled mode, and you can pass the defaultValue property as the default value.

Hide source code

Readonly & Disabled

readonly sets read-only status, and disabled sets disabled status. The internal <input> will be set to disabled in both cases. They differ almost only in style.

Disabled:
Readonly:
Hide source code

Loading State

loading sets the loading state, and a loading icon will be displayed.

Hide source code

Prompt Information

activeTip and inactiveTip set the text prompts inside the component. activeLabel and inactiveLabel set the text prompts on both sides of the component. Slot forms are also supported: active-tip, inactive-tip, active-label, inactive-label.

active-icon and inactive-icon set the icons of the switch.

Hide source code

Background Color

Set the background color through activeColor and inactiveColor.

Hide source code

Switch Size

The size property sets the size of the switch.

Hide source code

Switch Shape

The switch has two shapes: 'round' and 'rect', which are set via shape.

Hide source code

API

SwitchProps

AttributeTypeOptionalDefaultDescriptionVersion
modelValueboolean | nullTrueundefinedThe value of the switch (controlled mode), supports v-model.0.0.3
defaultValueboolean | nullTrueundefinedThe default value of the switch (uncontrolled mode).0.0.3
shape'round' | 'rect'True'round'The shape of the switch.0.0.3
size'small' | 'medium' | 'large'True'medium'The size of the switch.0.0.3
readonlybooleanTruefalseWhether it is read-only.0.0.3
disabledbooleanTruefalseWhether it is disabled.0.0.3
loadingbooleanTruefalseWhether it is in loading state.0.0.3
activeTipstringTrueThe text tip when selected, located inside the switch.0.0.3
inactiveTipstringTrueThe text tip when not selected, located inside the switch.0.0.3
activeLabelstringTrueThe text label when selected, located outside the switch.0.0.3
inactiveLabelstringTrueThe text label when not selected, located outside the switch.0.0.3
activeColorstringTrueThe label color when selected. See Supported Color Parsing.0.0.3
inactiveColorstringTrueThe label color when not selected. See Supported Color Parsing.0.0.3
pollSizeChangebooleanTruefalseEnables polling for component size changes. This also affects the property of the same name in data input components that are child components.0.1.0

SwitchEvents

EventParameterDescriptionVersion
update:modelValuevalue: booleanCallback for updating modelValue.0.0.3
inputvalue: boolean, event: InputEventCallback when the switch is triggered.0.0.3
changevalue: boolean, event: EventCallback when the switch's selection state changes.0.0.3
focusevent: FocusEventCallback when the switch is focused.0.0.3
blurevent: FocusEventCallback when the switch is blurred.0.0.3

SwitchSlots

SlotParameterDescriptionVersion
active-tipTip when selected, located inside the switch.0.0.3
inactive-tipTip when not selected, located inside the switch.0.0.3
active-labelText label when selected, located outside the switch.0.0.3
inactive-labelText label when not selected, located outside the switch.0.0.3
active-iconIcon when selected.0.0.3
inactive-iconIcon when not selected.0.0.3