Skip to content

Switch 开关

即时切换一个明确的二元状态。

基础用法

HUD 已开启
查看 Vue 源码
Vue · TypeScript
<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

属性类型默认值说明
modelValuebooleanfalse通过 v-model 更新
labelstring必填可见标签
disabledbooleanfalse禁止切换
namestringundefined表单字段名

事件

  • update:modelValue(boolean)

键盘操作与使用边界

Tab 聚焦,Space 或 Enter 切换。

安装

ts
import { AgmSwitch } from 'augma'
import 'augma/style.css'