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)