如何在 vuex 模块中编写异步函数
How to write an async function in a vuex module
我正在使用 Nuxt fetch()
lifecycle hook 从 Vuex 获取数据。我的商店结构如下所示
store/
--| index.js
--| dialog.js
--| country/
------| actions.js // I want to use async call in this file
------| getters.js
------| mutations.js
------| state.js
在我的组件中,我使用这样的 fetch
async fetch({ store }){
await store.dispatch("country/fetchCountries")
},
我的 country/actions.js 文件看起来像这样
export const fetchCountries = ({commit, dispatch}, form) => {
// let response = await this.$axios.get('/countries');
}
现在,我不能在函数前面使用async。如何在此函数前使用异步?
这个不行吗?
export const fetchCountries = async ({commit, dispatch}, form) => {
我正在使用 Nuxt fetch()
lifecycle hook 从 Vuex 获取数据。我的商店结构如下所示
store/
--| index.js
--| dialog.js
--| country/
------| actions.js // I want to use async call in this file
------| getters.js
------| mutations.js
------| state.js
在我的组件中,我使用这样的 fetch
async fetch({ store }){
await store.dispatch("country/fetchCountries")
},
我的 country/actions.js 文件看起来像这样
export const fetchCountries = ({commit, dispatch}, form) => {
// let response = await this.$axios.get('/countries');
}
现在,我不能在函数前面使用async。如何在此函数前使用异步?
这个不行吗?
export const fetchCountries = async ({commit, dispatch}, form) => {