Vue.js Vuex action“;“不是一个函数”;内部Nuxt获取

Vue.js Vuex action“;“不是一个函数”;内部Nuxt获取,vue.js,vuex,nuxt.js,Vue.js,Vuex,Nuxt.js,我刚刚在我的一个Nuxt页面中引入了错误处理,显然在fetch中映射和调用的操作会引发一个not a函数错误。如果try/catch块不在那里,它将按预期工作,并且完全没有错误 以下是我的部件,主要部分如下: 导出默认值{ 名称:“ViewArticle”, 异步获取({error}){ 试一试{ 等待this.fetchArticle({articleSlug:this.articleSlug}) }捕捉(错误){ 错误({statusCode:404,消息:'May the force wi

我刚刚在我的一个Nuxt页面中引入了错误处理,显然在
fetch
中映射和调用的操作会引发一个not a函数错误。如果
try
/
catch
块不在那里,它将按预期工作,并且完全没有错误

以下是我的部件,主要部分如下:

导出默认值{
名称:“ViewArticle”,
异步获取({error}){
试一试{
等待this.fetchArticle({articleSlug:this.articleSlug})
}捕捉(错误){
错误({statusCode:404,消息:'May the force with you'})
}
},
计算:{
…地图绘制者({
文章:“文章/单篇”
}),
第()条{
返回此。$route.params.articleSlug
}
},
方法:{
…映射操作({
fetchArticle:'article/fetchOne'
})
}
}
我假设mapActions只会在spiel中稍后执行,但无法找出如何防止错误。这样,基本上每次我加载页面时,它都会立即重定向到错误页面

我收到的错误消息如下。显然,
fetchArticle
是一个函数,除非它在
try
/
catch
块中,否则它会正常工作

this.fetchArticle is not a function                                                                                                               03:30:51

  at Object.fetch (52.js:32:18)
  at server.js:2881:39
  at Array.map (<anonymous>)
  at module.exports../.nuxt/server.js.__webpack_exports__.default (server.js:2864:51)
this.fetchArticle不是函数03:30:51
在Object.fetch(52.js:32:18)
在server.js:2881:39
在Array.map()处
在module.exports../.nuxt/server.js.\uuu webpack\uu exports\uuu.default(server.js:2864:51)
使用
异步获取({store})


Fetch提供
上下文作为参数

fetch(context)
在上下文中,我们可以找到我们的商店。在这里,您可以查看上下文包含的内容:

人们喜欢破坏它

fetch({ store }) {}
您的代码应该如下所示:

  async fetch ({ error, store }) {
    try {
      await store.dispatch('article/fetchOne', { articleSlug: this.articleSlug })
    } catch (err) {
      error({ statusCode: 404, message: 'May the force be with you' })
    }
  },
Fetch在服务器端执行,这就是为什么get
不是一个函数
错误。它没有定义

。。。在服务器端调用fetch


确切的错误消息是什么,please@Phil刚刚更新了我的问题,你使用的是什么版本的Nuxt?
fetch({ store }) {}
  async fetch ({ error, store }) {
    try {
      await store.dispatch('article/fetchOne', { articleSlug: this.articleSlug })
    } catch (err) {
      error({ statusCode: 404, message: 'May the force be with you' })
    }
  },