[Vuejs]-How can i access an index in vuejs

0👍

As order is an object, order % 2 === 0 will always return false and it applied the else class which is bg-light-grey.

You should apply condition on the iteration index. Change your logic to :

<div
    v-for="(order, index) in allOrders"
    :class="index % 2 === 0 ? 'bg-white' : 'bg-light-grey'"
    :key="index"
>
   {{ order.description }}
</div>

Leave a comment