我通过添加cdn链接创建了一个vue.js项目。我创建了两个名为A和B的组件。但我无法嵌套这两个组件。有没有什么方法可以像在cli-setup项目中那样嵌套这两个。
Vue.component('A',{template: '<p>Hello I am A</p>'})
Vue.component('B',{template: '<p>Hello I am B</p>'})
不要打电话给你的组件A
或B
。你的组件应该是:https://vuejs.org/v2/guide/components-registration.html
然后只重用另一个模板中的组件:
Vue.component('component-a',{template: '<p>Hello I am A</p>'})
Vue.component('component-b',{template: '<div><p>Hello I am B</p><component-a></component-a></div>'})
然后显示您的组件:
<div id="app">
<component-a></component-a>
<component-b></component-b>
</div>
和
new Vue({
el: "#app",
})