Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

86
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!