VSwitch ​

VSwitch wraps Element Plus ElSwitch and adds an awaited on-change callback, optional automatic loading state, and a custom extended switch style enabled by default.

Basic Usage ​

Use on-change to run side effects after the value changes.

Auto Loading ​

Keep the switch in loading state while the awaited on-change handler is running.

OFF

Complete example ​

Combine async state updates, guarded switching with before-change, string-based values, and custom action slots.

Async status sync
Disabled
Guarded release state
P
published
Custom action slots
Offline
Online
online

Behavior Notes ​

  • on-change is a prop callback, not a dedicated emitted event. It receives (value, closeLoading) after the inner switch value changes.
  • When auto-loading is true by default, VSwitch uses its internal loading state while on-change is running, so the loading prop is ignored.
  • Call closeLoading() inside on-change if you need to stop the internal loading state before the awaited handler finishes.
  • When auto-loading is false, use the regular loading prop for manual loading control.
  • custom-shape is enabled by default and applies the custom extended switch appearance from the theme styles.
  • Named slots are forwarded to ElSwitch, so active, inactive, active-action, and inactive-action are available.
  • model-value should match either active-value or inactive-value. If it does not, the underlying switch falls back to inactive-value.

API ​

VSwitch Attributes ​

NameDescriptionTypeDefault
model-value / v-modelswitch binding valueboolean / string / numberfalse
on-changeawaited callback invoked after value changefunction—
custom-shapeapply the custom extended switch stylebooleantrue
auto-loadingautomatically manage internal loading state while on-change is runningbooleantrue
disableddisable the switchbooleanfalse
loadingmanual loading state, used when auto-loading is falsebooleanfalse
sizeswitch sizeenum—
widthswitch widthnumber / string''
inline-promptshow prompt inside the switchbooleanfalse
active-action-iconicon for the action area when checkedstring / Component—
inactive-action-iconicon for the action area when uncheckedstring / Component—
active-iconicon when active, overrides active-textstring / Component—
inactive-iconicon when inactive, overrides inactive-textstring / Component—
active-texttext when activestring''
inactive-texttext when inactivestring''
active-valuevalue when activeboolean / string / numbertrue
inactive-valuevalue when inactiveboolean / string / numberfalse
nameinput name attributestring''
validate-eventtrigger form validationbooleantrue
before-changehook before value change, return false or reject to prevent the switch from togglingfunction—
idinput idstring—
tabindexinput tabindexstring / number—

VSwitch Events ​

NameDescriptionType
update:model-valuetriggered when value changesfunction

VSwitch Slots ​

NameDescription
activecontent shown for the active state label or prompt
inactivecontent shown for the inactive state label or prompt
active-actioncontent shown inside the action area when checked
inactive-actioncontent shown inside the action area when unchecked

Source ​

Docs