[Vuejs]-Iterating through vue array using index

2👍

When you use v-for, the first parameter will be the element of the array, and not the index. To get the index, you have to add parenthesis and a comma.

Here:

<div v-for="(el, index) in someObject.listA">

Then you can use the index.

0👍

index is the 2nd argument in a v-for

Inside v-for blocks we have full access to parent scope properties.
v-for also supports an optional second argument for the index of the
current item.

<ul id="example-2">
  <li v-for="(item, index) in items">
    {{ parentMessage }} - {{ index }} - {{ item.message }}
  </li>
</ul>

Leave a comment