我正在try 渲染Vue实例中的对象列表.每个对象都应该使用一个组件,所以我将该组件放入v-for-loop.但我得到的是list.title
和list.text
,而不是正确的值.
在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"},
...
]
}
})
谢谢