我是webcomponents的新手。由于webcomponents v1是可用的,我从那里开始。我已经阅读了关于他们网络的各种帖子。我特别感兴趣的是正确编写它们。我已经阅读了有关插槽并让它们工作,尽管我的努力并没有导致按我期望的方式工作的插槽web组件。编写v1嵌套的web组件
如果我有创作嵌套的Web组件这样,从嵌套/开槽WebComponent的DOM不会得到插入父的插槽:
<parent-component>
<child-component slot="child"></child-component>
</parent-component>
而这里的父WebComponent的HTML:
<div id="civ">
<style>
</style>
<slot id="slot1" name="child"></slot>
</div>
由于每个WebComponent的(父和子)被写入到是独立的,我已与创建它们:
customElements.define('component-name', class extends HTMLElement {
constructor() {
super();
this.shadowRoot = this.attachShadow({mode: 'open'});
this.shadowRoot.innterHTML = `HTML markup`
}
})
所得DOM包括2阴影根。我试图编写没有阴影dom的子/开槽元素,这也不会导致父主管dom托管孩子。
那么,构建v1嵌套webcomponents的正确方法是什么?