1)redux狀態管理
2)通過refs傳遞,代碼如下所示:
父組件代碼:
<QueryBox ref="queryBox" app={this.app} onSearch={this.onSearch} onCount={this.onCount} />
let QueryBoxInstance = this.refs.queryBox as QueryBox;
QueryBoxInstance.onChange();
3)通過回掉函數傳遞,代碼如下:
父組件
<AddModal
onOk={(score: any, review: any) => this.handleOk(score, review) as any}
onCancel={this.hideModal as any}
loading={this.state.loading}
studentInfo={this.state.studentInfo}
/>
子組件
<Modal
visible={true}
title="評分"
onOk={()=>{
this.props.onOk(this.state.score,this.state.review)
}}
onCancel={this.props.onCancel}
confirmLoading={this.props.loading}
okText="確認"
className="review"
cancelText="取消"
>