Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda