2
我想呈现一个来自我的Vue实例的对象列表。每个对象应该使用一个组件,所以我把组件放入v-for-loop。但我得到的是list.title
和list.text
而不是正确的值。VueJS - v-for内的组件
在v-for-loops中使用组件有特殊的方法吗?
我发现这个thread in the Vue-Forum,但不知道如何使用它或如果它是正确的方式。
应用:
<div id="app">
<div v-for="list in lists">
<listcard title="list.title" text="list.text"></listcard>
</div>
</div>
模板:
<template id="listcard-template">
<div class="card">
<h2>{{ title }}</h2>
<p>{{ text }}</p>
</div>
</template>
我的组件:
Vue.component('listcard', {
template: '#listcard-template',
props: ['title', 'text']
})
Vue公司-实例:
new Vue({
el: "#app",
data: {
lists: [
{title: "title1", text: "text1"},
{title: "title2", text: "text2"},
...
]
}
})
谢谢!