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)
}

相关文章:

  • 2022-12-23
  • 2021-10-23
  • 2022-03-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案