获取taro的checkbox的选中状态

Posted on 2020-11-05 22:17  猫头唔食鱼  阅读(1052)  评论(0编辑  收藏  举报
import React, { Component } from 'react'
import { View, Text ,Checkbox} from '@tarojs/components'
export default class Index extends Component {
  constructor(props){
    super(props)
    this.state = {
      checked:false
    }
  }
  handleClick = ()=>{
    this.setState({
      checked:!this.state.checked
    })
  }
  render() {
    return (
      <View>
        <Checkbox onClick={this.handleClick} checked={this.state.checked}></Checkbox>
        {/* 要toString不然小程序上不显示 */}
        是否选中 : {this.state.checked.toString()}
      </View>
    )
  }
}