使用 我的应用 也是一种 支持 我的方式:
DockLift: 点击 Dock 应用窗口回到当前屏幕 Zipora: Zip/RAR/7Z 解压工具 Scap: Screenshot & Markup Edit Screen Test Deskmark Keyzer Vidwall Hub VidCrop Vidwall Mousio Hint Mousio Musicer Audioer FileSentinel FocusCursor Videoer KeyClicker DayBar Iconed Menuist Quick RSS Quick RSS Web Serve Copybook Generator DevTutor for SwiftUI RegexMate Time Passage Iconize Folder Textsound Saver Create Custom Symbols DevHub Resume Revise Palette Genius Symbol Scribe

Switch 开关 === [![Buy me a coffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-048754?logo=buymeacoffee)](https://jaywcjlove.github.io/#/sponsor) [![Telegram Channel](https://img.shields.io/badge/%20-Telegram-00618f.svg?logo=Telegram)](https://t.me/s/AwesomeMacApps) [![Follow On X](https://img.shields.io/badge/Follow%20on%20X-333333?logo=x&logoColor=white)](https://x.com/jaywcjlove) [![Open in unpkg](https://img.shields.io/badge/Open%20in-unpkg-blue)](https://uiwjs.github.io/npm-unpkg/#/pkg/@uiw/react-switch/file/README.md) [![NPM Downloads](https://img.shields.io/npm/dm/@uiw/react-switch.svg?style=flat)](https://www.npmjs.com/package/@uiw/react-switch) [![npm version](https://img.shields.io/npm/v/@uiw/react-switch.svg?label=@uiw/react-switch)](https://npmjs.com/@uiw/react-switch) 表示两种相互对立的状态间的切换,多用于触发「开/关」。选中时的内容支持响应式。 ```jsx import { Switch } from 'uiw'; // or import Switch from '@uiw/react-switch'; ``` ### 基本用法 ```jsx mdx:preview&bg=#fff import React from 'react'; import { Switch } from 'uiw'; export default function Demo() { return (
电源
); } ``` ### Form 中使用 Switch ```jsx mdx:preview&bg=#fff import React from 'react'; import { Form, Switch, Row, Col, Button, Notify } from 'uiw'; export default function Demo() { return (
{ }} resetOnSubmit={false} onSubmitError={(error) => error && error.filed ? { ...error.filed } : null} onSubmit={({initial, current}) => { console.log('switch::', initial, current) const ErrObj = {}; if(Object.keys(ErrObj).length > 0) { const err = new Error(); err.filed = ErrObj; throw err; } }} fields={{ switch: { checked: true, initialValue: true, label: '请输入内容', help: '必选选项!', validator: value => !value ? '必填选项!' : null, children: , }, }} > {({ fields, state, canSubmit }) => { return (
{fields.switch}
                  {JSON.stringify(state.current, null, 2)}
                
); }} ); } ``` ### 设置文字 ```jsx mdx:preview&bg=#fff import React from 'react'; import { Switch } from 'uiw'; export default function Demo() { return (
{ console.log('e', e.target.checked); }} style={{ marginRight: 10 }} />
); } ``` ### 禁用状态 ```jsx mdx:preview&bg=#fff import React from 'react'; import { Switch } from 'uiw'; export default function Demo() { return (
电源
); } ``` ### 尺寸 ```jsx mdx:preview&bg=#fff import React from 'react'; import { Switch } from 'uiw'; export default function Demo() { return (
电源
); } ``` ### 控制组件 通过 `checked` 属性改变 `Switch` 组件状态。 ```jsx mdx:preview&bg=#fff import React from 'react'; import { Switch, Button } from 'uiw'; class Demo extends React.Component { constructor(props) { super(props); this.state = { checked: true } } onChange(e) { console.log('~~~:::'); this.setState({ checked: e.target.checked }); } render() { return (
) } } export default Demo; ``` ## Switch | 参数 | 说明 | 类型 | 默认值 | |------ |-------- |---------- |-------- | | value | 根据 value 进行比较,判断是否选中 | String/Number/Boolean | - | | name | 用于表单对应的名称 | String | - | | checked | 指定当前是否选中 | boolean | false | | disabled | 是否禁用 | boolean | false | | onChange | 变化时回调函数 | Function(e:Event) | - | | data-checked | 选中时的内容 | string/ReactNode | - | | data-unchecked | 非选中时的内容 | string/ReactNode | - | | size | 开关大小,可选值:`large` `default` `small` | string | default |