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

217
Visualizações
How to run a v-for loop on root <template> component to loop through imported components [Vue 3]

I am using a headless WordPress build with Nuxt. The WordPress build contains many "flexible" components which have an attribute called "acf_fc_layout" which will determine the name of the component.

The way my loop works is basically, loop through the REST Api, and for example, if "acf_fc_layout" is equal to "article_block", render "ArticleBlock.vue" as a component. This way, our client can add and remove components as they please.

The problem is, I am trying to run a for loop to render out these components, but when I run the below code, I am told "acf_fc_layout is undefined".

Although, IF I add a parent HTML node, and loop through that (for example, ), it works fine.

Problem is, I do not want a parent HTML node for each component. I want to JUST render the component only.

Where am I going wrong with this?

Code:

<template v-for="(section, index) in sections" :key="`section-${index}`">
  <!-- eslint-disable vue/no-v-html -->
  <MediaAndText
    v-if="section.acf_fc_layout === 'image_text'"
    :section="section"
  />
  <FullSizeImage
    v-else-if="section.acf_fc_layout === 'full_size_media'"
    :section="section"
  />
  <GoogleMap
    v-else-if="section.acf_fc_layout === 'google_map'"
    :section="section"
  />
  <StatsBlock
    v-else-if="section.acf_fc_layout === 'stats_block'"
    :section="section"
  />
  <!--eslint-enable-->
</template>

<script>
import FullSizeImage from './sections/FullSizeImage.vue'
import StatsBlock from './sections/StatsBlock.vue'
import MediaAndText from '~/components/sections/MediaAndText.vue'
import GoogleMap from '~/components/sections/GoogleMap.vue'

export default {
  name: 'SectionSelector',
  components: {
    MediaAndText,
    FullSizeImage,
    GoogleMap,
    StatsBlock
  },
  props: {
    sections: {
      default: () => {},
      type: Array
    }
  },
}
</script>

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

0

Try to wrap your <template v-for="..."> within a template:

<template>
    <template v-for="..." :key="...">
        ...
    </template>
</template

The <template> will act as a parent node, but will not be rendered

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