假设我在商店中有以下操作:
actions: {
async actionA ({ commit }) {
commit('gotData', await getData())
},
async actionB ({ dispatch, commit }) {
await dispatch('actionA') // wait for `actionA` to finish
commit('gotOtherData', await getOtherData())
},
async actionC ({ commit }) {
commit('gotExtraData', await getData())
},
... and many more.
注意:所有都是独立的动作。 现在,我想在代码的不同级别上分派多个操作。 这是我目前的工作方式。
await Promise.all([this.$store.dispatch(`${storeUrl}/actionA`,
this.$store.dispatch(`${storeUrl}/actionC`), ...and many more)]`;
我可以使用一个调度语句来调用操作,而不是那么多单独的调度调用? 像这样的东西:
await this.$store.dispatch(storeUrl, [...all individual actions here]);