繁体   English   中英

如何在 vuex 模块中编写异步 function

[英]How to write an async function in a vuex module

我正在使用 Nuxt fetch()生命周期挂钩从 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'); 

}

现在,我不能在 function 前面使用 async。 我如何在这个 function 前面使用异步?

这个不行吗?

export const fetchCountries = async ({commit, dispatch}, form) => {

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM