Skip to content

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 ​

ParameterDescriptionTypeOptionsDefault
modelValueSwitch state valueboolean—false
valueCustom valueboolean | string | number—false
sizeSizestringmini/supersmall/small/medium/large/biglarge/superlarge—
textTextstring——
disabledDisabled stateboolean—false

Events ​

Event NameDescriptionParameters
update:modelValueTriggered when state changes(value: boolean)

Type Definitions ​

typescript
interface SwitchProps {
  modelValue?: boolean;
  value?: boolean | string | number;
  size?: string;
  text?: string;
  disabled?: boolean;
}

Released under the MIT License.