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"},
...
]
}
})
謝謝!