【发布时间】:2016-02-10 13:12:25
【问题描述】:
我正在阅读学习 vue.js 的指南,到了关于道具的部分,然后遇到了一个问题。
我知道子组件具有独立的范围,我们使用 props 配置将数据从父组件传递到它,但是当我尝试它时,我无法让它工作。
我有the example I'm working on up on js fiddle:
var vm = new Vue({
el: '#app',
// data from my parent that I want to pass to the child component
data:{
greeting: 'hi'
},
components:{
'person-container':{
// passing in the 'greeting' property from the parent to the child component
props:['greeting'],
// setting data locally for the child
data: function (){
return { name: 'Chris' };
},
// using both local and parent data in the child's template
template: '<div> {{ greeting }}, {{ name }}</div>'
}
}
});
当我运行上面的代码时,我的输出只有:
,克里斯
子组件本地的数据渲染得很好,但是传入的父组件的数据要么没有通过,要么没有正确渲染。
我在 javascript 控制台中没有看到任何错误,并且模板正在呈现。
我是否误解了应该如何传递道具?
【问题讨论】:
标签: javascript vue.js