Home Web Front-end JS Tutorial Vue.JS introductory tutorial list rendering

Vue.JS introductory tutorial list rendering

Dec 03, 2016 am 10:30 AM
vue.js

You can use the v-repeat directive to render a list based on an array of objects on a ViewModel. For each object in the array, this directive will create a child Vue instance with that object as its $data object. These child instances inherit the data scope of the parent instance, so within repeated template elements you can access properties of the child instance as well as those of the parent instance. In addition, you can also get the array index corresponding to the current instance through the $index property.

<ul id="demo">
 <li v-repeat="items" class="item-{{$index}}">
 {{$index}} - {{parentMsg}} {{childMsg}}
 </li>
</ul>
Copy after login
var demo = new Vue({
 el: &#39;#demo&#39;,
 data: {
 parentMsg: &#39;Hello&#39;,
 items: [
  { childMsg: &#39;Foo&#39; },
  { childMsg: &#39;Bar&#39; }
 ]
 }
})
Copy after login

Check the effect, it should be easy to get the result

Block-level repetition

Sometimes we may need to repeat a block containing multiple nodes. In this case, we can use the