//子组件代码
render() {
return (
<div>
{/*当input的值改变时将子组件的值传给父组件,toFatherValue是父组件一个属性,用来接口子组件的值*/}
<input onChange={this.props.toFatherValue}/>
</div>
)
}
//父组件代码
render() {
return (
<div> {/*父组件接收子组件的值*/}
<EventComponet toFatherValue={this.getChildValue.bind(this)}/>
<div>从父组件接收过来的值:{this.state.childValue}</div>
</div> )
}
/**
* 获取从子组件传递过来的值
*/
getChildValue(e) {
console.log("getChildValue", e.target.value);
this.setState({
childValue:e.target.value
})
}