Skip to content

Switch 开关 ​

小程序端是 view 自绘

原生 switch 组件在小程序里样式不可控,用 view 自绘滑块保证视觉一致。

基础用法 ​

vue
<template>
  <lh-switch v-model="on" />
  <lh-switch v-model="on" active-text="开" inactive-text="关" />
  <lh-switch v-model="on" loading />
  <lh-switch v-model="on" disabled />
</template>

<script setup lang="ts">
import { ref } from 'vue'
const on = ref(true)
</script>

Props ​

属性说明类型默认值
modelValue (v-model)是否开启booleanfalse
disabled禁用booleanfalse
loading加载中booleanfalse
name原生 namestring—
size尺寸'small' | 'medium' | 'large'—
activeText开启文案string—
inactiveText关闭文案string—
customClass自定义类名string—
sx快速布局属性LhSxProps—

Events ​

事件说明回调参数
update:modelValue值变化(value: boolean)
change值变化(value: boolean)