Access Parent index property from nested v-for in a double level v-for
by RomainMazB
HTML
<html>
<body>
<div id="app">
<ul v-for="(current_array, index) in array">
<li v-for="(item, index) in current_array">{{ index }} is {{ item }}</li>
</ul>
</div>
<div v-for="property in test">
{{ property }}
</div>
</body>
</html>
JavaScript
var vm = new Vue({
el: '#app',
data: {
source_array: ['first item of first array', 'second item of first array',
'first item of second array', 'second item of second array',
'first item of third array', 'second item of third array'],
test: {is_this_working: true, well: false }
},
computed: {
array() {
let before_chunk_array = this.source_array;
let array_chunked = [];
while(before_chunk_array.length) {
array_chunked.push(before_chunk_array.splice(0, 2));
}
return array_chunked;
}
},
mounted() {
console.table(this.array);
}
});