diff --git a/packages/components/Switch/Switch.vue b/packages/components/Switch/Switch.vue index b0af6ed..e8f20b4 100644 --- a/packages/components/Switch/Switch.vue +++ b/packages/components/Switch/Switch.vue @@ -56,6 +56,8 @@ const switchStyle = computed(() => ({ const toggleChecked = () => { if (props.disabled || props.loading) return + if (props.beforeChange && !props.beforeChange()) return + emit('update:modelValue', !props.modelValue) } diff --git a/packages/components/Switch/switch.ts b/packages/components/Switch/switch.ts index 20a51c5..12a7906 100644 --- a/packages/components/Switch/switch.ts +++ b/packages/components/Switch/switch.ts @@ -13,6 +13,7 @@ export interface SwitchProps { offIcon?: string width?: string size?: ViBaseSizes + beforeChange?: () => boolean } export interface SwitchEmits {