Skip to content

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随控件事件触发表单校验booleantrue
v-model开关状态booleanfalse
label可见标签;隐藏标签使用 aria-labelstring—
active-text / inactive-text开启与关闭文字string''
inline-prompt在开关内部显示状态文字booleanfalse
width轨道宽度,数字按 px 处理string | number''
disabled禁止修改booleanfalse

事件 ​

事件说明
update:modelValueboolean,绑定值变化
changeboolean,用户切换开关状态
focus / blurFocusEvent,焦点变化

实例 ​

focus()、blur() 控制原生开关输入框焦点