【发布时间】:2015-11-13 09:52:39
【问题描述】:
我想将 Vue 的动态组件 (http://vuejs.org/guide/components.html#Dynamic_Components) 用于在子对象而不是父对象中定义的组件。例如:
new Vue({
el: 'body',
components: {
'post': require('./post')
});
// post.js
module.exports = {
inherit: true,
data: function () {
return {
currentView: 'create-post'
}
},
components: {
'create-post': require('./create-post'),
'update-post': require('./update-post')
}
}
<component is="{{ post.currentView }}"></component>
或者更好
<post is="{{ currentView }}"></post>
据我所知,由于父母是唯一可以访问<component> 标签的人,因此不可能使用第二级孩子。是我对结构的思考不正确,还是有办法完成上述操作?
【问题讨论】:
标签: vue.js