roymondchen 873a51fc87 docs: 升级 VitePress 至 v2 alpha,类型引用改为源码片段同步
- 升级 vitepress 到 ^2.0.0-alpha.17
- vite.optimizeDeps.rolldownOptions.transform.define 迁移至 vite.define 以适配 v2 API
- 同步升级 vitest/rolldown/vue/vite 等周边依赖
- 文档中类型链接统一改为 <<< 片段引用源码 region,避免 commit hash 链接失效
- packages/{core,editor,form-schema,schema,stage} 相关类型加 // #region 锚点
- 移除已废弃的 docs/guide/advanced/tmagic-ui.md 及侧栏入口

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-18 11:47:03 +08:00

66 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Switch 开关
表示两种相互对立的状态间的切换,多用于触发「开/关」。
## 基本用法
<demo-block type="form" :config="[{
type: 'switch',
name: 'switch',
text: '开关'
}]"></demo-block>
## 扩展的 value 类型
<demo-block type="form" :config="[{
type: 'switch',
name: 'switch',
text: '开关',
activeValue: 'on',
inactiveValue: 'off'
}]">
<template #source>
<p>
设置 activeValue 和 inactiveValue 属性,接受 Boolean , String 或 Number 类型的值。
</p>
</template>
</demo-block>
## 禁用状态
<demo-block type="form" :config="[{
type: 'switch',
name: 'switch',
text: '开关',
disabled: true
}]">
<template #source>
<p>
设置 disabled 属性,接受一个 Boolean设置 true 即可禁用。
</p>
</template>
</demo-block>
## Attributes
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
| -------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ |
| name | 绑定值 | string | — | — |
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
| active-value | switch 打开时的值 | boolean / string / number | — | true |
| inactive-value | switch 关闭时的值 | boolean / string / number | — | false |
::: details 查看 FilterFunction 及关联类型定义
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
:::
## 配置类型
::: details 查看 SwitchConfig 配置类型定义
<<< @/../packages/form-schema/src/base.ts#SwitchConfig{ts}
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
:::