vue js loop through array code example
Example 1: vue for loop
<ul id="v-for-object" class="demo">
<li v-for="value in object">
{{ value }}
</li>
</ul>
Example 2: v-for
<ul>
<li v-for="(item, index) in items">
{{ index }} - {{ item }}
</li>
</ul>
Example 3: vue v-for loop array
<script src="https://cdn.jsdelivr.net/vue/latest/vue.js"></script>
<div id="sample">
<div v-if = "private.folders!=null" v-for="folder in private.folders">
{{folder.name}}
<div v-for="check in folder.checks">
{{check.name}}
</div>
</div>
</div>
Example 4: v-for only getting one first value vuejs
<option v-for="(location, index) in locations" v-bind:value="location.id" v-bind:selected="index === 0">
{{ location.from }} - {{ location.to }}
</option>
Example 5: vue v-for loop array
new Vue({
el: '#sample',
data: {
private: {
folders : [{
name : 'folder1',
checks : [
{ name : 'check1.1' },
{ name : 'check1.2' }
]
},
{
name : 'folder2',
checks : [
{ name : 'check2.1' },
{ name : 'check2.2' }
]
}
]
}
}
})