Switch Component

Switch component is used to represent two mutually opposing states, and users can toggle between states by clicking.
Basic Usage
Basic switch usage, bind the switch value through v-model.
Disabled State
Set the disabled attribute to disable the switch.
Loading State
Set the loading attribute to display loading state.
Different Styles
Set the radius attribute to change the switch style, supporting default (circular) and square (square).
Custom Colors
Customize the switch background colors through onBgColor and offBgColor attributes.
Different Sizes
Switch supports three sizes: small, default, and large.
Custom Content
Use onContent and offContent slots to customize the switch content.
Event Handling
Switch provides a change event that is triggered when the state changes.
Switch API
Attributes
| Attribute | Description | Type | Accepted Values | Default |
|---|---|---|---|---|
| v-model | Binding value | boolean | — | — |
| size | Size | string | small / default / large | default |
| disabled | Whether disabled | boolean | — | false |
| loading | Whether in loading state | boolean | — | false |
| radius | Button border radius type | string | default / square | default |
| onBgColor | Background color when on | string | — | — |
| offBgColor | Background color when off | string | — | — |
Events
| Event Name | Description | Parameters |
|---|---|---|
| change | Triggered when state changes | (value: boolean) |
Slots
| Slot Name | Description |
|---|---|
| onContent | Content when on |
| offContent | Content when off |
Style Variables
The switch component uses the following style variables, which can be customized through SCSS variables:
| Variable Name | Description |
|---|---|
| $theme-color-primary | Theme color - Primary |
| $theme-color-danger | Theme color - Danger |
| $color-white | White color |
| $color-black | Black color |
| $bg-color-default | Default background color |
| $opacity-disabled | Disabled state opacity |
| $font-size-small | Small font size |
| $font-size-default | Default font size |
| $font-size-large | Large font size |
Tune UI