1 回答

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