1

当前文档中尚不清楚,因为fetch方法发生了很大变化。据我了解,在文档中它说:

fetch(context) 已被弃用,您可以在页面中使用匿名中间件:middleware(context)

所以context不再可用了?那么将什么传递给 fetch方法呢?

以及如何store访问context?比如2.12.2之前,我们可以使用fetch如下方法:

// pages/index.vue
async fetch ({ store }) {
  await store.dispatch('....')
},

所以,我假设上面的代码将来不会很快在 Nuxt 3 中运行。那么当你在一个页面上时如何填充存储数据呢?

目前,您似乎仍然可以访问方法中context第一个参数。未来呢? fetch

4

1 回答 1

5

那么将什么传递给 fetch方法呢?

fetch钩子不再有任何参数。

你如何store访问context

要访问fetch钩子中的上下文,请使用this.$nuxt.context; 你可以store像这样访问:

const { store } = this.$nuxt.context
store.dispatch(...)

// or
this.$nuxt.context.store.dispatch(...)
于 2020-06-23T19:15:11.200 回答