Hướng dẫn javascript components without framework

  • April 3, 2020
  • Patrick Jahr

  • JavaScript, Web Components

Everyone knows it: encapsulating and reusing UI components on the web is challenging. It is usually copy and paste of HTML, CSS, and JavaScript, often spread over one or more files. If you forget a part, it either does not look as desired, or the interaction will not work. Enough of that! Web Components open up new ways on the web to implement and (re-)use UI components in a standardized manner and without any framework.

In this article:

Hướng dẫn javascript components without framework

Patrick Jahr is architect at Thinktecture and focuses on Blazor WebAssembly, .NET Core and Angular.

What to expect

  • Learn how to create a native Web Component without using a framework
  • Explanation of all steps and essentials points like HTML Templates, Custom Elements and shadow DOM to create a Web Component, based on a sample built with Visual Studio Code.

Hướng dẫn javascript components without framework

What are Web Components?

Web Components are a collection of three technologies:

  • HTML Templates
  • Custom Elements
  • Shadow DOM

With these three technologies, it is possible to develop native Web Components. For the components part, this may lead us to a solution where we might not need to use full-blown frameworks like Angular, React, or Vue.js.

Create your Web Component template with HTML Templates

With HTML Templates, you can create your template markup. In order to use a template, you simply have to write your markup inside the