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

157
Vistas
How to use array props in Vue 3?

Trying to learn the basics, I got an array in the parent component (App.vue)

data() {
 return {
  fruits: [
    "apple",
    "pear",
    "cherry" 
  ], 
 };
},

I want to be able to have the same component 3 times for each fruit

<Fruit  v-for="(fruit, index) in fruits" :key="index"/>

And this is the props feature Fruit.vue component (the child component)

 props: {
  fruits: {type: Array, required: false},
}

How should I write the code so it displays each fruit in their "own" component in the tag of Fruit.vue

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You want to have a fruit component that accepts only a string from the array.

Fruit component

<template>
<div class="fruit">
{{ props.fruit }} 
</div>
</template>

<script lang="ts"
export default defineComponent({
  props: {
    fruit: { type: String, required: true }
  }
  setup(props) {
    return { props }
  }
}
</script>

inside app.vue

<Fruit  v-for="fruit in fruits" :key="fruit" :fruit="fruit"/>
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