> For AI agents: the complete documentation index is available at /apps-plugin/docs/llms.txt, the full documentation bundle is available at /apps-plugin/docs/llms-full.txt.

# switch

开关切换组件，用于二元状态（开/关）的交互控制。

<iframe src="https://developer.doubao.com/docs-preview/component-simulator/?caseId=switch"
  title="组件示例 switch"
  width="100%"
  height="700"
  loading="lazy"
  style="width:100%;height:700px;border:0;border-radius:16px;overflow:hidden;"
></iframe>

## 扫码预览

![扫码预览 switch](https://api.qrserver.com/v1/create-qr-code/?size=200x200\&data=doubao%3A%2F%2Fdoubao_apps%3Fapp_id%3Ddb_1McM5Ni%26path%3D%252Fpages%252Fcomponent%252Fswitch%252Findex)

## Props

<table>
<thead>
<tr><th width="140">属性名</th><th width="240">类型</th><th width="120">默认值</th><th width="80">必填</th><th width="360">说明</th></tr>
</thead>
<tbody>
<tr><td>checked</td><td><code>boolean</code></td><td>-</td><td>否</td><td>是否选中。如果设置了 <code>checked</code>，则 Switch 将处于受控模式，此时 <code>defaultChecked</code> 将被忽略。</td></tr>
<tr><td>className</td><td><code>string</code></td><td>-</td><td>否</td><td>组件类名</td></tr>
<tr><td>defaultChecked</td><td><code>boolean</code></td><td>false</td><td>否</td><td>默认选中状态，仅在非受控模式下生效</td></tr>
<tr><td>disabled</td><td><code>boolean</code></td><td>false</td><td>否</td><td>是否禁用。当为 <code>true</code> 时用户无法操作</td></tr>
<tr><td>key</td><td><code>string | number | null</code></td><td>-</td><td>否</td><td>React key 属性</td></tr>
<tr><td>onChange</td><td><code>(checked: boolean) =&gt; void</code></td><td>-</td><td>否</td><td>状态变化时的回调函数</td></tr>
<tr><td>size</td><td><code>SwitchSize</code></td><td>'large'</td><td>否</td><td>尺寸</td></tr>
<tr><td>style</td><td><code>CSSProperties</code></td><td>-</td><td>否</td><td>组件样式</td></tr>
</tbody>
</table>
