Skip to content

Switch ​

开关。v-model;sizes;disabled;role="switch"。

基础 ​

md v-modelon
disabled ondisabled off

sizes

vue
<script setup lang="ts">
import { ref } from 'vue'
import { HSwitch } from 'happier-ui'

const on = ref(true)
</script>

<template>
  <h-switch v-model="on" aria-label="示例开关" />
</template>

API ​

Props ​

名称类型默认说明
modelValuebooleanfalse是否打开
disabledbooleanfalse禁用(不切换)
size'sm' | 'md' | 'lg''md'尺寸
ariaLabelstring—可访问名称(建议填写)

Emits ​

事件载荷说明
update:modelValueboolean切换后的值

Slots ​

无。

无障碍 ​

  • role="switch" + aria-checked
  • 建议提供 ariaLabel
  • disabled 时不切换;:focus-visible

MIT License