请注意,这是我的代码的非常简化的示例。我有一个状态:
list_image.BeginUpdate();
list_image.Items.Remove(item);
list_image.Items.Insert(newIndex, item);
list_image.EndUpdate();
我想这样改变我的状态:
this.state = {
first: "",
second: "",
third: ""
}
res.data是:
this.getAppData(localStorage.getItem("application_id")).then(res => this.setState( prevState => {
...prevState.state,
res.data
}))
答案 0 :(得分:0)
这就是答案,所有res.data键值现在都覆盖匹配的状态值:
this.getAppData(localStorage.getItem("application_id")).then(res =>
this.setState({ ...this.state, ...res.data })
);
答案 1 :(得分:0)
尝试一下
this.getAppData(localStorage.getItem("application_id")).then(res =>
this.setState((state) => ({ ...state, ...res.data }))
);