1 回答

TA貢獻1827條經驗 獲得超9個贊
父組件獲得了數據后 將你的數據存儲在父組件的state當中 ,然后向子組件傳遞通過state去傳遞就好了
如:
//父組件 Parent
class Parent extends React.Component{
constructor(props){
super(props);
this.state={
parentDate:""
}
}
handle(){
//在這里請求拿到數據然后進行存儲
this.setState({
parentDate:"XXXX"
})
}
render(){
return (
<Child parentDate={this.state.parentDate}/>
)
}
//子組件
class Child extends React.Component{
constructor(props){
super(props);
}
componentWillReceiveProps(nextProps){
//在這里可以將接受到的props去存在子組件內
}
render(){
return (
<div>{"I get : "+this.props.parentData}</div>
)
}
}
}
添加回答
舉報