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

252
Visualizações
Vue: How to get rid of duplicate content

I have an array of names using v-for I get the names, as you can see I have two v-fors where the content is duplicated in this example my content is small and doesn't look so scary in real life it can be much bigger and all the problem is that the content is repeated, I tried to apply slots but could not cope

Template

<template>
  <div>
    <div v-for="(item, index) in array" :key="index" class="names">
      <div class="show-names">
        <p>{{ item.name }}</p>
      </div>
      <div
        v-for="(girlNames, index) in item.girlNames"
        :key="index"
        class="names"
      >
        <div class="show-names">
          <p>{{ girlNames.name }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

Script

<script>
export default {
  data() {
    return {
      array: [
        { name: "Alex" },
        { name: "Jacob" },
        { name: "Robert" },
        {
          girlNames: [
            {
              name: "Anna",
            },
            {
              name: "Kiwi",
            },
            {
              name: "Ava",
            },
          ],
        },
      ],
    };
  },
};
</script>

Yes, this picture shows where the content is repeated

enter image description here

You can also see code example in codesandbox

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

0

The only problem I see here is bad data structure. In my opinion it should be an object with two fields, which seperate in your case boys and girls, and in this object should be actual data:

<script>
export default {
  data() {
    return {
      names: {
          boys: [
              { name: "Alex" },
              { name: "Jacob" },
              { name: "Robert" },
            ],
          girls: [
              { name: "Anna" },
              { name: "Kiwi" },
              { name: "Ava" },
            ]
          }
        },
      ],
    };
  },
};
</script>

They your code in template will be like:

<template>
  <div>
    <div class="names">
      <div v-for="(item, index) in name.boys" :key="index" class="show-names">
        <p>{{ item.name }}</p>
      </div>
      <div v-for="(item, index) in name.girls" :key="index" class="show-names">
        <p>{{ item.name }}</p>
      </div>
    </div>
  </div>
</template>
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