Код: Выделить всё
class MyElem extends HTMLElement {
constructor() {
super();
let templateContent = document.getElementById('template-elem').content;
this.innerHTML = templateContent.cloneNode(true);
}
}
window.customElements.define('my-elem', MyElem);Код: Выделить всё
b
c
Почему это не работает? В инспекторе Chrome пользовательский элемент не содержит HTML. Я также пробовал:
Код: Выделить всё
this.append(templateContent.cloneNode(true));
Во всех руководствах упоминается использование теневого DOM, например:
Код: Выделить всё
this.attachShadow({mode: 'open'}).appendChild(templateContent.cloneNode(true));
Подробнее здесь: https://stackoverflow.com/questions/650 ... tachshadow
Мобильная версия