react 组件传值

1、分父亲向儿子传值

2、子向父亲传值

3、没有嵌套关系的组件之间传值,例如兄弟组件传值


1.父组件向子组件传值  
(通过props来传值,这种应用,很多时候我们某个组件在不同的地方用到,但是就只是内容不一样,这样在调用组件就是父组件的时候给各自自己的值就好)
//子组件
class Es6cComponent extends React.Component{
constructor(props){
super(props);
}
render(){
return(
<div>
<div>{this.props.nameall}</div>
</div>
)
}
}
//父组件
class App extends React.Component{
render(){
return(
<div>
<Es6cComponent nameall="abc"/>
</div>
)
}
}

2.子组件给父组件传值 ( 回调函数)

react 传值方式

3.兄弟组件传值(子组件传给父组件,由父组件再传给另外一个子组件)

react 传值方式

 

相关文章:

  • 2021-12-20
  • 2022-12-23
  • 2021-08-24
  • 2021-06-08
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
  • 2022-12-23
相关资源
相似解决方案