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

151
Visualizações
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 Respostas
Responde à pergunta

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