Custom elements are fun technology. In this video, you will learn how to set one up and running in less than 2 minutes.

You'll learn how to create a Custom Web Element (that extends HTMLElement) that renders text to the browser and respond to a click event listener.

 

class MyCustomElement extends HTMLElement {
  constructor() {
    super();
    this.addEventListener("mouseover", () => console.log("Hello World"));
  }

  //lifecycle
  connectedCallback() {
    this.innerHTML = `<h1>Hello Custom ELement</h1>`;
  }
}

window.customElements.define("zwt-element", MyCustomElement);
<!DOCTYPE html>
<html>

<head>
    <title>Custom Element</title>
    <meta charset="UTF-8" />
</head>

<body>
    <div id="app"></div>
     <zwt-element [msg]="greeting"   />
    <script src="src/index.js">
    </script>
</body>

</html>

 

More about custome element

相关文章:

  • 2021-12-25
  • 2021-04-18
  • 2021-12-26
  • 2021-10-08
  • 2021-10-25
  • 2021-08-28
猜你喜欢
  • 2022-12-23
  • 2021-06-08
  • 2022-12-23
  • 2021-07-28
  • 2021-08-17
  • 2021-12-31
  • 2022-12-23
相关资源
相似解决方案