1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
class HelloWorld extends HTMLElement { constructor() { super(); const shadowRoot = this.attachShadow({ mode: 'open' }); shadowRoot.innerHTML = this.template(); } template() { return ` <style> h1{ color: #f00; } </style>
<h1>组件元素</h1> <!-- <edo-header></edo-header> --> `; } connectedCallback() { console.log('template element is connected'); } disconnectedCallback() { console.log(1111); } adoptedCallback() { console.log(22222); }
attributeChangedCallback() { console.log(3333333); } } customElements.define('hello-world', HelloWorld);
|