vuejs v-for array code example

Example 1: vuejs v-for array index

<!-- To gain access to the array index: -->
<ul>
    <li v-for="(game, index) in games"></li>
</ul>
<!--
	You only want the index in specific cases. Use `:key` as
	standard. See the other greps.
-->

Example 2: vue js v-for array index

<ul>
  <li v-for="(val, index) in arr">
    <!-- Do something... -->
  </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: 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' }
          ]
        }
      ]
    }
  }
})

Tags:

Misc Example