Hello,
I found out in the VueJS documentation about lists, only $index exists as a special property in template lists. AngularJS has 6: $index, $first, $middle, $last, $even and $odd which I found really convenient.
For example, instead of writing this code:
<ul>
<li v-for="item in items" :class="{'last': $index === items.length - 1}"
</ul>
We would write:
<ul>
<li v-for="item in items" :class="{'last': $last}"
</ul>
Avoiding the well-known-and-always-the-same logic to know if we are talking about the last element or not, or the first element, or an odd element, etc...
Is it possible to get this part of VueJS 1.x.x?
Thanks!
Jerome
(No comment on Vue 1)
In Vue 2 I don't see this being very feasible due to the v-for="(item, index) in items" syntax.
Maybe you could just write helper methods instead and add them in each component that needs them?
$index is deprecated in 2.0 in favor of a more explicit syntax: (item, index), because it has been concluded long ago that magically injected variables like $index will be a mess if you are in nested v-for(ng-repeat).
So please use the current solution you're using, it's only a few characters longer but everything is more explicit and won't give you any surprises, and you have full control of what's going on.
Most helpful comment
$index is deprecated in 2.0 in favor of a more explicit syntax:
(item, index), because it has been concluded long ago that magically injected variables like $index will be a mess if you are in nested v-for(ng-repeat).So please use the current solution you're using, it's only a few characters longer but everything is more explicit and won't give you any surprises, and you have full control of what's going on.