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

83
Views
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 answers
Answer question

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 Report

0

You can put index:

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