Skip to content

Switch 开关

表示两种状态之间的切换。

基础用法

当前值: false
vue
<template>
  <x-switch v-model="value" />
</template>

<script setup>
import { ref } from 'vue'
const value = ref(false)
</script>

禁用状态

vue
<template>
  <x-switch v-model="value" disabled />
</template>

自定义颜色

vue
<template>
  <x-switch v-model="value" active-color="#13ce66" inactive-color="#ff4949" />
</template>

API

Props

属性说明类型默认值
modelValue绑定值boolean | number | stringfalse
disabled是否禁用booleanfalse
width宽度number | string40
activeColor打开时的背景色string'#409eff'
inactiveColor关闭时的背景色string'#dcdfe6'
activeValue打开时的值boolean | number | stringtrue
inactiveValue关闭时的值boolean | number | stringfalse

Events

事件名说明回调参数
update:modelValue值改变时触发(value: boolean | number | string)
change值改变时触发(value: boolean | number | string)

基于 MIT 许可发布