Switch
Introduction
The switch component is used for users to toggle between two states. mengyue-components has encapsulated this component and conducted vitest testing. You can use <MYSwitch></MYSwitch> or <MYSwitch /> to implement a switch.
Basic Usage
Use v-model to bind the switch state.
Code Demo
展开代码
Switch with Text
Use text to define the text displayed on the switch.
Code Demo
展开代码
Custom Text Content
Use slots to customize the text content of the switch.
Code Demo
展开代码
Sizing
Use size to define the size, with multiple sizes provided by mengyue-components.
Code Demo
展开代码
Disabled State
Disabled Switch
Use disabled to disable the switch.
Code Demo
展开代码
API Reference
Props
| Parameter | Description | Type | Options | Default |
|---|---|---|---|---|
| modelValue | Switch state value | boolean | — | false |
| value | Custom value | boolean | string | number | — | false |
| size | Size | string | mini/supersmall/small/medium/large/biglarge/superlarge | — |
| text | Text | string | — | — |
| disabled | Disabled state | boolean | — | false |
Events
| Event Name | Description | Parameters |
|---|---|---|
| update:modelValue | Triggered when state changes | (value: boolean) |
Type Definitions
typescript
interface SwitchProps {
modelValue?: boolean;
value?: boolean | string | number;
size?: string;
text?: string;
disabled?: boolean;
}