这就是我的state
样子:
constructor(props, context) {
super(props, context);
this.state = {
show: false,
btnLabel: 'GO!',
car: {
owner: false,
manufacturer: false,
color: false
}
};
}
这就是我修改的方式state
:
handleClickFetchPrice() {
this.setState({btnLabel: 'Fetching data...' });
console.log(this.state.fetchPriceBtn);
const url = 'some url';
axios.get(url)
.then(res => {
let car = [...this.state.car];
car.owner = res.data.owner;
car.manufacturer = res.data.manufacturer;
car.color = res.data.color;
this.setState({car});
})
}
属性car
已更新,但未更新fetchPriceBtn
- 的输出console.log(this.state.fetchPriceBtn);
仍然是GO!
。
我在看什么?为什么fetchPriceBtn
不更新?