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

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

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

eg:console

子组件中传递数据:<button onClcik={()=>{this.change(value)}}></button>
change=(value)=>{
this.props.handleClick();
}
父组件中接收数据:
<Son handleClick={this.handleClick}></Son>
handleClick=(value)=>{
console.log(value)
}方法

相关文章
相关标签/搜索