Switch 开关
即时切换一个明确的二元状态。
基础用法
查看 Vue 源码
<script setup lang="ts">
import { AgmSwitch } from 'augma'
import { shallowRef } from 'vue'
const enabled = shallowRef(true)
</script>
<template>
<div class="example-stack">
<AgmSwitch v-model="enabled" label="显示 HUD" />
<output>{{ enabled ? 'HUD 已开启' : 'HUD 已关闭' }}</output>
<AgmSwitch label="不可用开关" disabled />
</div>
</template>
<style scoped>
.example-row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 16px;
}
.example-stack {
display: grid;
gap: 24px;
width: 100%;
max-width: 360px;
}
</style>
API
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
modelValue | boolean | false | 通过 v-model 更新 |
label | string | 必填 | 可见标签 |
disabled | boolean | false | 禁止切换 |
name | string | undefined | 表单字段名 |
事件
update:modelValue(boolean)
键盘操作与使用边界
Tab 聚焦,Space 或 Enter 切换。
安装
ts
import { AgmSwitch } from 'augma'
import 'augma/style.css'