如题:父组件A里包含一个checkbox,现在需要点击checkbox将是否选中状态(true/false)保存到checkFlg这个变量中同时传递到子组件B中
代码如下:
父组件A
checkInfo = (e)=>{ //该方法是点击checkbox调用的方法
this.setState({
checkFlg:e.target.checked
});
// this.state.checkFlg = e.target.checked;
console.log('选中状态1:' + this.state.checkFlg);
}
// 引入子组件B
<ActiveForm name1={this.state.checkFlg}/>
子组件B
<p>选中状态为:{this.props.name1}</p>
目前效果如下图(只需要关注红方框)
https://reactjs.org/tutorial/...
this.props.name1.toString()
https://codesandbox.io/s/0vm4...