Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

87
Vistas
VueJs dynamic slot key best pratice

In my VueJs 2 application, I'm refactoring my code that use with named slots (to follow recommendations as :slot attribute is deprecated) from:

<CustomComponent>
  <div slot="named-slot">foo</div>
</CustomComponent>

to:

<CustomComponent>
  <template #named-slot>
    <div>foo</div>
  </template>
</CustomComponent>

But I have a problem with dynamic slots. Before, I had:

<Slider :nb-slides="3">
  <Slide v-for="n in 3" :key="n" :slot"`slide-${n}`" :someDynamicProp="...">
</Slider>

And when refactoring code, I have some issues with :key. If I put :key in template:

<Slider :nb-slides="3">
  <template v-for="n in 3" :key="n" #[`slide-${n}`] >
    <Slide :someDynamicProp="...">
  </template>
</Slider>

I got the following error:

ERROR  Failed to compile with 1 errors                                                       

Module Error (from ./node_modules/vue-loader/lib/loaders/templateLoader.js):
(Emitted value instead of an instance of Error) 

  Errors compiling template:

  <template> cannot be keyed. Place the key on real elements instead.

And if I put :key in the concrete element Slide:

<Slider :nb-slides="3">
  <template v-for="n in 3" #[`slide-${n}`] >
    <Slide :key="n" :someDynamicProp="...">
  </template>
</Slider>

I got the following error:

error  `<template v-for>` key should be placed on the `<template>` tag  vue/no-v-for-template-key-on-child

So as the second error is an EsLint error, I decided to add <!-- eslint-disable vue/no-v-for-template-key-on-child --> comment to be able to build, but I'm wondering what is the best pratice in this case?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda