Mohammad Babaei
Mohammad Babaei

Reputation: 493

How to use @nuxt/content inside Component?

I'm trying to nuxt-contnt inside a component it works well in page with asyncData but not working inside the component

this works fine :

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

 return {
   page,
  }
 },
}

but this is not working :

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

 },
}

Upvotes: 0

Views: 282

Answers (1)

Jimmar
Jimmar

Reputation: 4459

fetch doesn't have any parameters but has access to this, so it should be

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

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

Upvotes: 1

Related Questions