0

我正在尝试在一个组件中使用 nuxt-contnt 它在带有 asyncData 的页面中运行良好,但在组件内部却无法运行

这很好用:

export default {
 async asyncData({ $content }) {
 const page = await $content('hello').fetch()

 return {
   page,
  }
 },
}

但这不起作用:

 export default {
 data() {
  return {
  content: [],
 }
 },
 async fetch({ $content }) {
  this.content = await $content('hello').fetch()

 },
}
4

1 回答 1

1

fetch没有任何参数但可以访问this,所以应该是

async fetch() {
  this.content = await this.$content('hello').fetch()
 }

https://nuxtjs.org/docs/features/data-fetching/

于 2022-01-10T22:48:29.063 回答