【发布时间】:2020-03-01 18:27:47
【问题描述】:
我可以在setState行前后console.log(data),但没有成功设置confirmationDetail的状态,但是购物车可以工作。
const init = {
method: 'POST',
body: JSON.stringify(information),
headers: { 'Content-Type': 'application/json' }
};
fetch('api/orders', init)
.then(response => response.json())
.then(data => {
if (!data.error) {
this.setState(state => ({ cart: [], confirmationDetail: data }));
} else {
Swal.fire(data.error);
}
});
}```
【问题讨论】:
-
你能分享你的状态对象吗
-
this.state = { cart: [], confirmationDetail: {} }
标签: javascript reactjs api fetch