๐Ÿ”ฐweb component

isolated pieces (kinds of blocks) with which a user interface (UI) can communicate with other elements, through properties and events.

web โŸฉ component

Web Component ๅ…่จฑไฝ ่‡ชๅฎš HTML ๅ…ƒ็ด ๏ผŒๅฐ่ฃไบ† HTML ็ตๆง‹ใ€CSS ๆจฃๅผๅ’Œ JavaScript ่กŒ็‚บใ€‚

web components are implemented as a custom element that uses a <template> tag for efficiency and a shadow root for encapsulation.

cheatsheet

๐Ÿ“ html

<!-- โญ๏ธ 1. custom element -->
<my-component></my-component>

<!-- โญ๏ธ 2. customized built-in element -->
<!-- โญ๏ธ   `is="my-componet"` attribute -->
<button is="fancy-button">some text</button>

๐Ÿ“ js

// โญ๏ธ 2. `new MyComponent()`
let button = new FancyButton();

// โญ๏ธ 3. `document.createElement('my-component')` 
//                                            โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โญ๏ธโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
let button = document.createElement('button', {is: 'fancy-button'});

button.textContent = 'Fancy button!';
button.disabled = true;
document.body.appendChild(button);

Last updated