🔰web component

web ⟩ component

宣告方式

1️⃣ 定義 custom element

先定義一個繼承 HTMLElementcustom element (class):

// ⭐️ 1️⃣ custom element
class MyComponent extends HTMLElement {
  constructor() {
  
    // ⭐️ 呼叫父類別的 constructor
    super(); 

    // 在這裡初始化你的 component
  }
}

使用方式

📁 HTML:使用自訂元素 (custom element)

📁 JS:定義並宣告

Last updated

Was this helpful?