-
父组件向子组件传值
- 父组件
<Es6cComponent nameall="abc"/>
- 子组件
通过构造器进行接受props,然后使用super继承 constructor(props){ super(props); } 子组件如何使用 this.props.nameall
- 父组件
-
子组件向父组件传值
- 子组件
子组件的方法 handerClick(){ changeColor方法必须和父组件的方法同名 this.props.changeColor('green') } 子组件调用 <button onClick={(e)=>{this.handerClick(e)}}>更改父组件的颜色</button> ```
- 父组件
父组件的方法 bgChange(color){ this.setState({ bgColor:color }) } 父组件传入方法 <Children bgColor={this.state.bgColor} changeColor={(color)=>{this.bgChange(color)}}>更改父组件的颜色</Children> ```
- 子组件
-
兄弟组件传值(子组件传给父组件然后在传给另外一个组价)
react组件传值
最新推荐文章于 2023-07-29 16:30:00 发布