React 父组件和子组件中的方法相互调用
生活随笔
收集整理的這篇文章主要介紹了
React 父组件和子组件中的方法相互调用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 父組件調用子組件方法
- 子組件調用父組件方法
父組件調用子組件方法
父組件中調用子組件的getTree方法
父組件
setFormValue=()=>{this.TreeList.getTree}<TreeList onSelect={this.setFormValue} onRef={(ref) => { this.TreeList = ref }} />子組件
componentDidMount = () => {this.props.onRef(this);this.getTree()}getTree=()=>{}子組件調用父組件方法
子組件中調用父組件的setId方法
父組件
<NavBarXitem={item}current={current}getBatchDetails={(id) => this.getBatchDetails(0, id)}setId={(id, callback) => this.setState({ id }, callback)}onRef={this.onNavBarXRef}/>子組件
this.props.setId(prePageId, () => {getBatchDetails(prePageId)})總結
以上是生活随笔為你收集整理的React 父组件和子组件中的方法相互调用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: React 学习笔记 —— Ref Ho
- 下一篇: antd react dva在model