【发布时间】:2018-02-21 10:03:48
【问题描述】:
如何让这两个组件协同工作?
Vue.component('parent', {
template: ''+
'<slot name="foo"></slot>'+
''
});
Vue.component('child', {
template: ''+
'<div slot="foo">bar</div>'+
''
});
我以为我可以做这样的事情,但它似乎不起作用
Vue.component('parent', {
components: [
'child'
],
template: ''+
'<slot name="foo"></slot>'+
''
});
这是一个 JS Fiddle https://jsfiddle.net/3fjmLL52/
【问题讨论】:
-
你想做什么?
-
我已经添加了一个 JS Fiddle ......抱歉我还是 vue 的新手
-
你想让孩子在父母内部呈现吗?
-
是的,我希望插槽或“模板”像占位符一样位于父级中,然后将子级的内容转储在那里