我应该在 Vuex 存储操作中使用 async/await 吗?
Should I use async/await in Vuex store actions?
在 Nuxt 的 Vuex 存储操作中使用 async
/await
是一个好习惯还是没用,为什么?
export const actions = {
async getFoo({ state, commit }) {
await this.$axios.get('api/foo').then((res) => {
commit('FOO_SETUP', res.data)
})
}
}
是的,随心所欲地使用它们,这就是操作的重点(与必须同步的突变相比)
你也可以等待他们
await dispatch('getFoo')
在 Nuxt 的 Vuex 存储操作中使用 async
/await
是一个好习惯还是没用,为什么?
export const actions = {
async getFoo({ state, commit }) {
await this.$axios.get('api/foo').then((res) => {
commit('FOO_SETUP', res.data)
})
}
}
是的,随心所欲地使用它们,这就是操作的重点(与必须同步的突变相比)
你也可以等待他们
await dispatch('getFoo')