[英]Vue components inside cycle
我覺得這個問題有點傻,但老實說我現在無法自己找到它。
我的問題是當我嘗試使用
…
<tbody v-for="body in bodies">
<row-c v-for="row in body.rows">
…
bodies
是
bodies: [
{
someOther: 'smth',
rows: [
{title: 'b1r1'},
{title: 'b1r2'},
{title: 'b1r3'}
]
},
{
someOther: 'smthElse',
rows: [
{title: 'b2r1'},
{title: 'b2r2'},
{title: 'b2r3'}
]
}
]
我收到錯誤
[Vue warn]: Error in render: 'TypeError: body is undefined'
但是沒有組件它可以工作: CodePen example without error 。
當然,我已經閱讀了錯誤消息中引用的文檔,但不明白我應該如何更改我的代碼。 請給我建議:)
提前致謝。
我剛剛根據Giovane 的回答更新了第一個 codepen ,並且沒有更多錯誤。
好吧,當你使用 DOM 模板時,你應該看看DOM Template Parsing Caveats
為了使您的示例正常工作,您應該使用<tr>
is
的屬性:
<tbody v-for="body in bodies">
<tr is="row-c" v-for="row in body.rows" v-bind:row="row"></tr>
</tbody>
並在row-c
中添加row
屬性:
Vue.component('row-c', {
props: ['row'],
data: function() {
return {
body: ''
}
},
template: "#row-c-template"
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.