Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

326
Visualizações
How to access Nuxt context inside of fetch() hook?

I want to access the props inside the async fetch() but I'm also using async fetch(context). So, I'm not sure how to access the props.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

In Nuxt 2, you have 2 fetch hooks.

The old one, before Nuxt 2.12, fetch(context) which acts a lot like asyncData. It's executed before the component creation, so you don't have access to it (data, props, options... nothing).
This one is deprecated, use asyncData instead.

The new one, from Nuxt 2.12, fetch() (with no parameters). It's executed at the same time as the created() hook. It has access to the component's context (props, data, etc.).

fetch(context) {
  // "this" doesn't exists
  // context is the Vue global context
}

fetch() {
  this.myProp // "this" exists and have access to props
}
about 4 years ago · Juan Pablo Isaza Relatório

0

As shown in the documentation, you can access the context with this when using the fetch() hook like

async fetch() {
  await this.$axios // or whatever this.$i18n etc.....
}

Don't use fetch(context) as explained here.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda