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

80
Vistas
How to use the key special attribute inside the v-for directive using an array of arrays
  1. List item

A have variable that contains an array of arrays of objects like this :

let FooVar: Array<Array<FooObject>> = [] ;

i want to loop through it inside a component something like this

<span v-for="item in FooVar" :key="XXX">

what should i put inside the key attribute ?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

As said in the documentation

The key special attribute is primarily used as a hint for Vue's virtual DOM algorithm to identify vnodes when diffing the new list of nodes against the old list.

It will also be used for

  • Properly trigger lifecycle hooks of a component
  • Trigger transitions

The only requirements is that your keys must not have any duplicates

Children of the same common parent must have unique keys. Duplicate keys will cause render errors.


In general the best way is by adding an unique identifier to the item with for example an id comming from the database

<span v-for="item in FooVar" :key="item.id">

If you don't have any id, then you can use the index of the item in the list.

Note that this is NOT optimzed and see here why

<span v-for="(item, index) in FooVar" :key="index">
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can put index:

<span v-for="(item, index) in FooVar" :key="index">
about 4 years ago · Juan Pablo Isaza Denunciar
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