Skip to main content
Version: 3.x

Switch

开关选择器

支持情况:

参考文档

类型

ComponentType<SwitchProps>

示例代码

export default class PageView extends Component {
constructor() {
super(...arguments)
}

render() {
return (
<View className='components-page'>
<Text>默认样式</Text>
<Switch checked/>
<Switch/>
<Text>推荐展示样式</Text>
<Switch checked/>
<Switch/>
</View>
)
}
}

SwitchProps

参数类型默认值必填说明
checkedbooleanfalse是否选中
disabledbooleanfalse是否禁用
type"switch" or "checkbox""switch"样式,有效值:switch, checkbox
colorstring"#04BE02"switch 的颜色,同 css 的 color
onChangeCommonEventFunction<onChangeEventDetail>checked 改变时触发 change 事件
nativePropsRecord<string, unknown>用于透传 WebComponents 上的属性到内部 H5 标签上

API 支持度

API微信小程序百度小程序支付宝小程序字节跳动小程序H5React Native
SwitchProps.checked✔️✔️✔️✔️✔️✔️
SwitchProps.disabled✔️✔️
SwitchProps.type✔️✔️✔️✔️✔️✔️
SwitchProps.color✔️✔️✔️✔️✔️✔️
SwitchProps.onChange✔️✔️
SwitchProps.nativeProps✔️

onChangeEventDetail

参数类型
valueboolean