store the id for each <input> in v-for as my index

Viewed 207

I have created several inputs using v-for and would like each input to have a unique id corresponding to the index. You can see my current code below:

<div v-for = "(item, index) in data" v-bind:key = "item">
    {{data[index][0]}} : {{item[1]}} <br>
    <input id = "index" placeholder =0 type="number" min="0">
<br><br> </div>

initially, I have used

<div v-for = "(item, index) in data" v-bind:key = "item">
    {{item[0]}} : {{item[1]}} <br>
    <input id = "index" placeholder =0 type="number" min="0">
<br><br> </div>

but VueJS require us to use the index as I have declared it in v-for. Also, my var data is a 2D array. Am i correct to put " id = "index" " in each input? I believe it is wrong as i cannot access the element using document.getElementById("0").value or document.getElementById(0).value

Thank you

0 Answers
Related