title: Switch

sidebar_label: Switch

开关选择器

属性

属性名 类型 默认值 说明
checked Boolean false 是否选中
type String switch 样式,有效值:switch, checkbox
color Color switch 的颜色,同 css 的 color

各端支持度

属性 微信小程序 H5 ReactNative 百度小程序 支付宝小程序 字节跳动小程序
checked
type
color
示例:
  1. import Taro, { Component } from '@tarojs/taro'
  2. import { View, Text, Switch } from '@tarojs/components'
  3. export default class PageView extends Component {
  4. constructor() {
  5. super(...arguments)
  6. }
  7. render() {
  8. return (
  9. <View className='components-page'>
  10. <Text>默认样式</Text>
  11. <Switch checked/>
  12. <Switch/>
  13. <Text>推荐展示样式</Text>
  14. <Switch checked/>
  15. <Switch/>
  16. </View>
  17. )
  18. }
  19. }