Skip to content

Switch ​

Switch is used for switching between two opposing states.

Basic usage ​

Bind v-model to a Boolean typed variable.

Types ​

There are two types of switches: circle and round.

Effects ​

Switch provide five different themes: outset、inset、bordered、outlined and flat. Using effect to change, default is outset.

Disabled ​

Adding the disabled attribute disables Switch.

Text description ​

Adding the active-text and inactive-text attribute to show texts. use inline-prompt attribute to control text is displayed inside dot.

Off
On

Display custom icons ​

Adding the active-icon and inactive-icon attribute to show icons. use inline-prompt attribute to control icon is displayed inside dot.

Extended value types ​

Setting the active-value and inactive-value attributes. They both receive a Boolean, String or Number typed value.

Loading ​

Setting the loading attribute to true indicates a loading state on the Switch.

Prevent switching ​

Setting the before-change property, If false is returned or a Promise is returned and then is rejected, will stop switching.

Sizes ​

Besides default size, tu-switch component provides three additional sizes for you to choose among different scenarios. Use attribute size to set additional sizes with mini, small, large.

Switch API ​

Switch Attributes ​

NameDescriptionTypeDefault
v-modelBinding value, it should be equivalent to either active-value or inactive-value, by default it's boolean typeBoolean String Numberfalse
disabledWhether Switch is disabledBooleanfalse
loadingWhether Switch is in loading stateBooleanfalse
typeType of SwitchStringcircle
effectEffect of SwitchStringoutset
sizeSize of SwitchStringmedium
widthWidth of SwitchString Numberfalse
inline-promptWhether icon or text is displayed inside dot, only the first character will be rendered for textBooleanfalse
active-valueSwitch value when in on stateBoolean String Numbertrue
inactive-valueSwitch value when in off stateBoolean String Numberfalse
active-iconComponent of the icon displayed when in on state, overrides active-textString Component-
inactive-iconComponent of the icon displayed when in off state, overrides inactive-textString Component-
active-textText displayed when in on stateString''
inactive-textText displayed when in off stateString''
nameInput name of SwitchString''
validate-eventInput name of SwitchBooleantrue
before-changeBefore-change hook before the switch state changes. If false is returned or a Promise is returned and then is rejected, will stop switchingBoolean Function-
idId for inputString-
tabindexTabindex for inputString Number-

Switch Events ​

NameDescriptionType
changeTriggers when value changesFunction

Switch Exposes ​

NameDescriptionType
focusManual focus to the switch componentFunction