I am really new to Vue and for one project I am trying to create an array of objects according to a number. For example, if the total length value is 3 then is there a way to create fetchList1, fetchList2 and fetchList3? If the total length value is 2 then it should create the data return object as fetchList1 and fetchList2.
I am getting the total length value from database so it can be more than 50 and less than 5 sometimes.
VIEW
<div id="app">
<button @click="grabTeams()">
CLICK ME
</button>
</div>
Method
new Vue({
el: "#app",
data: {
totalLength: '3',
fetchList1: '',
/** if the total length is 3 then it should automatically create fetchList1, fetchList2 and fetchList3 **/
},
methods: {
toggle: function(todo){
todo.done = !todo.done
},
grabTeams(){
console.log('Total value length ' +this.totalLength);
for(let b=0; b < this.totalLength; b++){
console.log('value of '+b);
var replyDataObj1 = parseInt(b);
replyDataObj1={
"id" : b
}
this['fetchList'+b] = replyDataObj1;
}
},
}
})
Below is the link that I tried on jsfiddle