I'm working with BootstrapVue.
I'm looping over an array, check the index of my array (indexArray) with the index of my component (indexChild) and then it should write the value which is in my indexArray in my b-form-input v-model.
How can I transform this code into a computed function? I know that I have to filter it but I don't know how to solve that .
<div v-for="(ID, indexChild) in 3" :key="indexChild">
<div v-for="(item, indexArray) in Array" :key="indexArray">
<div v-if="indexArray == indexChild">
<b-form-input type="number" :v-model="item"></b-form-input>
</div>
</div>
</div>
my Array console.log:
(3) ['1234', '4321', '1379']
▼
0: "1234"
1: "4321"
2: "1379"
Just return an item in your array by index that you already know, no need to iterate:
computed: {
itemOfInterest(){
return this.yourArray[this.indexChild]
}
}
To address the update in the original post. You can still do this in your template
<template>
<div v-for="(ID, indexChild) in 3" :key="indexChild">
<b-form-input type="number" :v-model="Array[indexChild]"></b-form-input>
</div>
</template>