【发布时间】:2018-03-13 04:30:40
【问题描述】:
我想将provide 和inject 传递给可以使用slot 递归地包含自身的“page-section”组件。
目标是这些“页面部分”组件中的每一个都将其id 连接在其余传递下来的ID(由/ 分隔)之后,以创建所有包含组件的路径。
其中一些“页面部分”还可能包含其他类型的组件。
这是我尝试失败的方法:
Vue.component('text-input', {
props: ['text', 'id'],
template: '<input type="text" :value="text"',
inject: ['sectionPath']
});
Vue.component('page-section', {
props: ['id'],
template: '<div><slot></slot></div>',
inject: {
sectionPath: { default: '/' }
},
provide: {
sectionPath: this.sectionPath + '/' + this.id
}
}
});
【问题讨论】:
标签: vue.js vue-component