vuejs
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
List Rendering 23<br />
4.2 v-for<br />
In order to loop through each item in an array, we will use v-for Vue’s directive.<br />
The v-for loop works on arrays/objects and is used to loop through each item in an array. This<br />
directive requires a special syntax in the form of item in array where array is the source data<br />
Array and item is an alias for the Array element being iterated on.<br />
Warning<br />
If you are coming from the php world you may notice that v-for is similar to php’s foreach<br />
function. But be careful if you are used to foreach($array as $value).<br />
Vue’s v-for is exactly the opposite, value in array.<br />
The singular first, the plural next.<br />
4.2.1 Range v-for<br />
Directive v-for can also take an integer. Whenever a number is passed instead of an array/object,<br />
the template will be repeated as many times as the number given.<br />
1 <br />
2 <br />
3 <br />
5 Hello Vue<br />
6 <br />
7 <br />
8 <br />
9 The multiplication table of 4.<br />
10 <br />
11 <br />
12 {{ i }} times 4 equals {{ i * 4 }}.<br />
13 <br />
14 <br />
15 <br />
16 <br />
17 <br />
18 <br />
19 new Vue({<br />
20 el: '.container'<br />
21 })