【发布时间】:2019-03-15 14:46:19
【问题描述】:
在下面的示例中,我需要在 fetch 方法中调用 fetchData 之前重置一些值。 async await 是否等待 reset 方法中的所有函数完成后再继续?
fetch = async () => {
await this.reset();
this.props.fetchData();
};
reset = () => {
this.props.resetFilter();
this.props.resetClient();
this.props.resetUser();
};
或者您是否必须执行以下操作?
fetch = () => {
this.reset().then(() => {
this.props.fetchData();
});
};
reset = async () => {
await this.props.resetFilter();
await this.props.resetClient();
await this.props.resetUser();
};
谢谢:)
【问题讨论】:
-
重置函数返回一个承诺?
-
@MohammedAshfaq 不,他们不返回承诺。它们是在 reducer 中重置值的操作
标签: javascript reactjs async-await es6-promise