ts ref的使用


ref的作用在於父組件取到子組件的所有state內容。

在父組件中 編寫如下:

1.  public child: any; 類中定義child,用於存放子組件的作用域

2. 綁定子組件作用域

public onRef(ref: any) {
this.child = ref
}
3. 子組件中綁定ref   <Childpage  
onRef={this.onRef}  /
>
4. onRef  綁定this       this.onRef = this.onRef.bind(this)
 
在子組件中 編寫如下:
  在constructor 中  onRef 綁定this 
this.props.onRef(this)
 之后在 父組件中可以隨便調用子組件的state中的值 , 調用方法 
  this.child.state.......


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM