Home > OS >  How to use @nuxt/content inside Component?
How to use @nuxt/content inside Component?

Time:01-11

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()

 },
}

CodePudding user response:

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/

CodePudding user response:

i guess it's better to use Axios

https://nuxtjs.org/examples/modules/axios#axios-usage

  •  Tags:  
  • Related