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

158
Vistas
difference between v-for structures

Could someone explain what is the difference between those 2 v-for structures:

<li v-for="item in items" :key="item">
</li>

and

<li v-for="(item, i) in items" :key="i">
</li>

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

In the first case, the v-for iterates over all elements of items. It assigns the :key to the item itself. This is not ideal if you have duplicate elements in items, because each :key should be unique.

In the second case, v-for also iterates over all elements of items, but it introduces another variable named i, which represents the numerical index of the item in items. This index is then assigned to :key. This is better, because the indexes can't be duplicate.

over 4 years ago · Santiago Trujillo Denunciar

0

As the purpose of :key attribute is to give a hint for Vue virtual DOM algorithm about change detection happen. Essentially, it helps Vue identify what's changed and what hasn't.

To understand it better I am adding the uses of both the scenarios :

  • :key="item" - If item is having unique value. So that each iterated element will get assigned with unique key.

    Demo screenshot

  • :key="index" - If item is not having unique value. Hence, to assigned unique key to each iterated element we are using index.

    Demo screenshot

over 4 years ago · Santiago Trujillo 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