MOCKSTACKS
EN
Questions And Answers

More Tutorials









VueJs List Rendering

Examples

Basic Usage


A list can be rendered using the v-for directive. The syntax requires that you specify the source array to iterate on, and an alias that will be used to reference each item in the iteration. In the following example we use items as the source array, and item as the alias for each item.

HTML


<div id="app">
 <h1>My List</h1>
 <table>
 <tr v-for="item in items">
 <td>{{item}}</td>
 </tr>
 </table>
</div>

Script


new Vue({
 el: '#app',
 data: {
 items: ['item 1', 'item 2', 'item 3']
 }
})

Only render HTML items


In this example will render five
<li>
tags
<ul id="render-sample">
 <li v-for="n in 5">
 Hello Loop
 </li>
</ul>

Pig countdown list


<ul>
 <li v-for="n in 10">{{11 - n}} pigs are tanning at the beach. One got fried, and
</ul>

Iteration over an object


v-for can be used for iterating over an object keys (and values):

HTML:


<div v-for="(value, key) in object">
 {{ key }} : {{ value }}
</div>

Script:


new Vue({
 el: '#repeat-object',
 data: {
 object: {
 FirstName: 'John',
 LastName: 'Doe',
 Age: 30
 }
 }
})


Conclusion

In this page (written and validated by ) you learned about VueJs List Rendering . What's Next? If you are interested in completing VueJs tutorial, your next topic will be learning about: VueJs Mixins.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.