vue学习笔记-列表渲染

<ul id="example-1">
  <li v-for="item in items"> {{ item.message }} li> ul>
var example1 = new Vue({
  el: '#example-1',
  data: { items: [ { message: 'Foo' }, { message: 'Bar' } ] } })
效果:
Foo
Bar


    "example-2">
  • for="(item, index) in items"> {{ parentMessage }} - {{ index }} - {{ item.message }}
var example2 = new Vue({ el: '#example-2', data: { parentMessage: 'Parent', items: [ { message: 'Foo' }, { message: 'Bar' } ] } }) 效果: Parent-0-Foo Parent-1-Bar

 

遍历对象的所有属性

    "v-for-object" class="demo">
  • for="value in object"> {{ value }}
new Vue({ el: '#v-for-object', data: { object: { title: 'How to do lists in Vue', author: 'Jane Doe', publishedAt: '2016-04-10' } } }) 结果: How to do lists in Vue Jane Doe 2016-04-10

 

三个参数作为索引:

for="(value, name, index) in object"> {{ index }}. {{ name }}: {{ value }}
结果:
0.title: 'How to do lists in Vue',
1.author: 'Jane Doe',
2.publishedAt: '2016-04-10'
 

 

你可能感兴趣的:(vue学习笔记-列表渲染)