Here is an example of the simplest web component which outputs “Hello World!“.
To include this on the page we simply add the following to our HTML (or in this case our markdown):
And here is the code:
A simple web component with attributes
Outputs the following:
And below is code for accepting attributes/props. Note the two newly added methods (plus the updated string interpolation output).
The first method is a static method where the prop names can be defined:
and the second is an attribute change callback method used to assign new values to our prop names:
The full component code: