vue template v-for code example

Example 1: vue list render in

<ul id="example-1">
  <li v-for="item in items" :key="item.message">
    {{ item.message }}
  </li>
</ul>

Example 2: vue v-for object

// object: {
//   title: 'How to do lists in Vue',
//   author: 'Jane Doe',
//   publishedAt: '2016-04-10'
// }
<div v-for="(value, name, index) in object">
  {{ index }}. {{ name }}: {{ value }}
</div>

Example 3: 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 4: vue js v-for array index

<ul>
  <li v-for="(val, index) in arr">
    <!-- Do something... -->
  </li>
</ul>

Example 5: 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>

Tags: