I have a table that retrieves some JSON from the Laravel API to populate rows. I use VueJS and v-repeat :
<tbody>
<tr v-repeat="entry: entries">
<td>@{{ entry.id }} </td>
<td>@{{ entry.distance }} km</td>
<td>@{{ entry.consumption }} l</td>
<td>@{{ getPrice(entry) + ' €'}}</td>
<td>@{{ getCost(entry) + ' €'}}</td>
<td>@{{ getAverageConsumption(entry) + ' l' }}</td>
<td>@{{ getAverageCost(entry) + ' €' }}</td>
<td>@{{ getCostPerDay(entry) + ' €' }}</td>
<td>@{{ this.getDate(entry) }}</td>
</tr>
</tbody>
Now I want to calculate the value of AverageCostPerDay (). The problem is that I need to access the previous item in an iteration in order to compare how many days have passed.
How do I access previous items using v-repeat in VueJS? And what might my getCostPerDay () method look like ?
source
share