VueJS: How to Access the Previous Item in v-repeat

In v2 of vue.js, you need to this form of v-for to get the index:

v-for="(item, index) in items"

You can then use items[index - 1] to get the previous value (making sure your function checks it isn't undefined).


You can use the $index variable along with entries like this

        <td>@{{ getCostPerDay(entries[$index-1]) + ' €' }}</td>

For more reading about $index have a look at Displaying Lists


<div v-for="grade, i in grades">
    <input v-model="grade.name">
    <input v-model.number="grade.percent">
    <div v-if="i > 0 && grade.percent > grades[i - 1].percent">
        Invalid: percent must be lower than previous grade
    </div>
</div>