【发布时间】:2019-03-27 04:16:33
【问题描述】:
我有一个相当简单的设置,但由于这些错误而失败:
属性或方法“fruit”未在实例上定义,但 在渲染期间引用。确保此属性是反应性的 [等等]
渲染错误:“TypeError:无法读取未定义的属性‘名称’”
无法读取未定义的属性“名称”
不确定是否是因为 x-template 引用方法有问题。我看用的不多。
这是我的代码:
<div id="main">
<h1>Vue Component Prop Error</h1>
<script type="text/x-template" id="foo">
<p>{{fruit.name}}</p>
</script>
<my-thing :fruit="fruits[1]"></my-thing>
</div>
<script>
Vue.component('my-thing', {
template: '#foo',
props: {
fruit: Object
}
});
var app = new Vue({
el: '#main',
data: {
fruits: [{
id: 1,
name: 'apple'
},{
id: 2,
name: 'banana'
},{
id: 3,
name: 'carrot'
}]
}
})
</script>
我错过了什么? (我希望在屏幕上看到“香蕉”。)
【问题讨论】:
标签: vue.js