Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ajvanho's avatar
Level 14

add index to bind attribute

How to add index from v-for loop to attribute "someAttr"?

<input :someAttr=??? type="number" v-model="data" class="w-12 h-6 border rounded-lg appearance-none">
0 likes
4 replies
danimoya's avatar

The last @click reply it's totally fine to me. Also, to extend the reply, if you want to use the index of a v-for with an object, you can also do it this way, for example:

<div 
    v-for="(value, key, index) in someObject" 
    :key="index"
    :someAttr="index"
>
    {{index}}.- {{key}}: {{value}}
</div>

Please or to participate in this conversation.