TUI

0.3.7
Switch 开关组件
一个简洁的开关组件,支持禁用、颜色定制、双向绑定等特性,适用于功能开关场景。
基础用法
默认样式的开关,可绑定 boolean 值。支持 round 为经典圆角样式
示例代码
vue
<template>
  <TsSwitch v-model="defaultValue" />
  <TsSwitch v-model="defaultValue" round />
</template>

<script setup lang="ts">
  const defaultValue = ref(true);

</script>
颜色配置
通过 activeColorinactiveColor 自定义颜色。
示例代码
vue
<template>
  <TsSwitch v-model="customColor1" activeColor="#52c41a" inactiveColor="#d9d9d9" />
  <TsSwitch v-model="customColor2" activeColor="#fa541c" inactiveColor="#999999" />
</template>

<script setup lang="ts">
  const customColor1 = ref(true);
  const customColor2 = ref(false);
</script>
禁用状态
设置 disabledtrue ,并可自定义 disabledColor
示例代码
vue
<template>
  <TsSwitch v-model="disabledTrue" :disabled="true" />
  <TsSwitch v-model="disabledTrue" :disabled="true" disabledColor="#c0c0c0" />
</template>

<script setup lang="ts">
  const disabledTrue = ref(false);
</script>
自定义slot
提供自定义插槽active、inactive 来拓展功能
🌙
示例代码
vue
<TsSwitch v-model="disabledTrue" activeColor="#f6f6f6" inactiveColor="#f6f6f6">
  <template #active>🌞</template>
  <template #inactive>🌙</template>
</TsSwitch>

<script setup lang="ts">
  const disabledTrue = ref(false);
</script>
属性 Props
属性名
说明
类型
可选值
默认值
版本说明
v-model
绑定值,通常为 Boolean 类型
boolean
true / false
false
activeColor
开关开启时的颜色
string
任意合法颜色值
#409eff / dark:#000
inactiveColor
开关关闭时的颜色
string
任意合法颜色值
#d9d9d9 / dark:#bfbfbf
disabledColor
开关禁用状态下的颜色
string
任意合法颜色值
#e5e3e3 / dark:#e6e8e9
disabled
是否禁用该开关
boolean
true / false
false
round
是否开启圆角
boolean, string, null
true / false
false
插槽 Slots
插槽名
说明
active
开启状态的插槽
inactive
关闭状态的插槽