Range of numbers

To start off with lists, set up your JSFiddle like in the preceding recipe, adding Vue.js as a framework. Select Vue 2.2.1 (or Vue (edge)):

  1. In the JavaScript section, write:
        new Vue({el:'#app'})
  1. And in the HTML write:
        <div id="app">           <ul>             <li v-for="n in 4">Hello!</li>           </ul>         </div>

This will result in a list with Hello! written four times. In a few seconds your first list is complete, nice job!

We can write a countdown with this technique--in the HTML, replace the content of the <div> with the following:

<div id="app">   <ul>     <li v-for="n in 10">{{11-n}}</li>     <li>launch missile!</li>   </ul> </div>

Get Vue.js 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.