5、react中父子组件间如何传值?

1.父组件向子组件传递数据:父组件绑定属性值传给子组件,子组件通过this.props()接受。

2.子组件向父组件传递数据:子组件绑定一个方法,方法中通过this.props.父组件方法名(参数)传递给父组件,父组件通过该方法接受数据。

eg:

子组件中传递数据:<button onClcik={()=>{this.change(value)}}></button>

change=(value)=>{

this.props.handleClick();

}

父组件中接收数据:

<Son handleClick={this.handleClick}></Son>

handleClick=(value)=>{

console.log(value)

}