【发布时间】:2020-07-22 16:13:05
【问题描述】:
所以我正在尝试从父级的 componentDidMount() 调用 axios.get('{link here}'):
class Parent extends React.Component {
constructor(){
super();
this.state = {
stuff: []
}
}
componentDidMount() {
axios.get({link})
.then(res => {
this.setState({stuff: res.data})
}
}
render() {
return(
<Child stuff={this.state.stuff} />
)
}
然后是Child各种子组件,其中一个是这样的:
class Child extends React.Component {
constructor(props) {
super(props);
}
render() {
return(
//To access everything in the data of parent here in child component
)
}
即使父母在 console.log() 中显示数据,孩子也没有收到任何东西
【问题讨论】:
-
在您的 axios 调用中添加 .catch。代码似乎没问题,所以也许 axios 调用失败了。
标签: javascript json reactjs axios