Switch 开关
切换两种互斥状态。
基础用法
使用 v-model 绑定开关值。
查看代码收起代码
vue
<script setup lang="ts">
import { ZSwitch } from '@codex-proxy/ui'
import { ref } from 'vue'
const enabled = ref(true)
</script>
<template>
<ZSwitch v-model="enabled" aria-label="启用配置" />
</template>文字描述
设置 inline-prompt,将两种状态的文字显示在开关内。
查看代码收起代码
vue
<script setup lang="ts">
import { ZSwitch } from '@codex-proxy/ui'
import { ref } from 'vue'
const enabled = ref(true)
</script>
<template>
<ZSwitch v-model="enabled" aria-label="文字描述" active-text="开" inactive-text="关" inline-prompt />
</template>Switch API
属性
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
size | 组件尺寸,未指定时继承 | ComponentSize | 'default' |
validate-event | 随控件事件触发表单校验 | boolean | true |
v-model | 开关状态 | boolean | false |
label | 可见标签;隐藏标签使用 aria-label | string | — |
active-text / inactive-text | 开启与关闭文字 | string | '' |
inline-prompt | 在开关内部显示状态文字 | boolean | false |
width | 轨道宽度,数字按 px 处理 | string | number | '' |
disabled | 禁止修改 | boolean | false |
事件
| 事件 | 说明 |
|---|---|
update:modelValue | boolean,绑定值变化 |
change | boolean,用户切换开关状态 |
focus / blur | FocusEvent,焦点变化 |
实例
focus()、blur() 控制原生开关输入框焦点