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

204
Visualizações
Nuxt How to send async props

I've been having trouble with Nuxt2.15 (Vue.js). I want to send the data from parent component to child component that parent components fetched. And, I want to fetch another data from a child component by useing the data from the parent component. But props data is undefined in the child component. I tried to use "watch" and "computed" in the child component. But I couldn't make it work. I would appreciate it if someone can show me how to fix it.

Parent

<template>
  <div>
    <Child v-bind:exampleData="exampleData" />
  </div>
</template>

<script>
import Child from "./Child.vue";
export default {
  name: "Parent",
  components: {
    Child,
  },
  data() {
    return {
      exampleData: [],
    };
  },

  async created() {
    const exampleData = await fetchData();
    this.exampleData = exampleData
  },

};
</script>

Child

<template>
  <div><!-- show result data here  --></div>
</template>

<script>
export default {
  name: "Child",
  props: ["exampleData"],

  async created() {
    let abc = this.exampleData;
    // abc is undefined
    const resultData = await fetData(abc);
    this.result = resultData;
  },

  data() {
    return {
      result: [],
    };
  },

};
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try to use mounted() method instead of created() like this:

<template>
  <div><!-- show result data here  --></div>
</template>

<script>
export default {
  name: "Child",
  props: ["exampleData"],
  async mounted() {
    let abc = this.exampleData;
    // abc is undefined
    const resultData = await fetData(abc);
    this.result = resultData;
  },
  data() {
    return {
      result: [],
    };
  },
};

But, if the data passed from the parent is asynchronous or could be changed at some moment, I would recommend using the watch prop like this:

<template>
  <div><!-- show result data here  --></div>
</template>

<script>
export default {
  name: "Child",
  props: ["exampleData"],
  data() {
    return {
      result: [],
    };
  },
  watch: {
   exampleData() {
     const resultData = await fetData(this.exampleData);
     this.result = resultData;
   }
  }
};
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