Vue.js, a simple v-for / v-bind to add an index to a class name

I cannot find the syntax to scroll through my elements and give each “li” a class corresponding to the index. How it's done?

<li v-for="(item, idx) in items class="idx"">
</li>
+10
source share
1 answer

I think this will be the most readable (prefix added because the class cannot start with a digit).

<li v-for="(item, index) in items" :class="['index--${index}']"></li>

I also use an array because it always distracts me.

:class="'index--${index}'"
+23
source

Source: https://habr.com/ru/post/1657656/


All Articles