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

121
Visualizações
Passing slot to grandchild though dynamic component

I have a wrapper component(Wrapper.vue).

<component v-for="c of comps" :key="c.componentName" :is="c.componentName">
      <slot :name="c.componentName">
      </slot>
</component>

const comps = 
      [
        {
          componentName: "Child1",
        },
        {
          componentName: "Child2",
        }
      ];

Child1.vue is something like below

<template>
  <div class="hello">
    <slot name="top">Child1 slot top text</slot>
  </div>
</template>

Child2.vue is something like below

<template>
  <div class="hello">
    <slot name="top">Child2 slot top text</slot>
  </div>
</template>

I want to use the wrapper like below in App.vue

<Wrapper>
      <template slot="slot1">
        <template slot="top">Inner Content1</template>
      </template>
      <template slot="slot2">
        <template slot="top">Inner Content2</template>
      </template>
</Wrapper>

CodeSandbox Link:- https://codesandbox.io/s/mystifying-burnell-ir8un

It is showing default text from Child1 and Child2 not from App.vue What should be done to fix it?

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

0

I changed some code and this is the result. The changes I made:

  • you had nested the <template> tag inside App.vue.
  • the wrapper itself needed to have a template for slot named 'top' and inside this template I added a slot with the same name of the component

https://codesandbox.io/s/lucid-smoke-uzgn7?file=/src/App.vue

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