【发布时间】:2021-01-04 13:28:09
【问题描述】:
我对我的服务器进行了调用,该服务器期望从该调用返回一个对象。
constructor(props) {
super(props);
this.state ={todos: []};
}
componentDidMount() {
console.log("HELLO");
axios.get("http://localhost:4000/todos")
.then(response =>{
console.log(response.data); // this works
this.setState({todos: response.data});
})
console.log(this.state.todos); // this does not (why?)
}
【问题讨论】: