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

131
Visualizações
How to make parent data accessible to nested slots' props (Vue 2)?

On a high level let's say I have:

<parent>
    <template v-slot:content="{foo, bar}"> // foo/bar are just data from parent that contains "FOO" / "BAR"
         <child :v-text="foo" :someprop="bar === 'BAR'"> // foo and bar are accessible here
              <template v-slot:content>
                  <grandchild :v-text="foo" :someprop="bar === 'BAR'"> // foo and bar are no longer accessible here
                  </grandchild>
              </template>
         </child>
    </template>
</parent>

In this manner, I can pass any arbitrary data from parent's scope and the direct child can access that. However, if the child also has slots, that child's children will lose context of the grandparent slot (unless I manually expose from child the data that came from parent in its slot template, I guess). And these nested slots can even go deeper to great grand children.

Is there a solution for making parent data available to great grand children's prop values?

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

0

You can create a named slot inside of the slot template of the parent, within the intermediate component.

This example passes an item property back to the child

Parent Component

<slot name='content' :item='item'>
  Replace Me
</slot>

Middle Component

<parent>
  <template #content='{item}'>
    <slot name='content' :item='item' />
  </template>
</parent>

Child Component

<middle>
  <template #content='{item}'>
    the item is {{item}}
  </template>
</middle>
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