我可以在自定义元素中使用另一个自定义元素吗?可以吗它行得通吗?我想创建一个使用另一个自定义元素的自定义元素。
(function() {
const template = document.createElement("template");
template.innerHTML = `
<style>
</style>
<another-custom-element></another-custom-element>
`;
class customElement extends HTMLElement {
constructor() {
super();
let shadowRoot = this.attachShadow({
mode: 'open'
});
this.shadowRoot.appendChild(template.content.cloneNode(true));
}
connectedCallback() {
}
}
customElements.define('custom-element', customElement);
})();