feat(site, templates): use HTMLElement.dataset 🤗
This commit is contained in:
parent
9ebd6e7f3b
commit
b4c7bab3df
4 changed files with 26 additions and 21 deletions
|
@ -5,9 +5,12 @@ class HelloWorld extends HTMLElement {
|
|||
|
||||
connectedCallback() {
|
||||
let count = 0;
|
||||
this.onclick = () => {
|
||||
this.setAttribute("data-name", `Clicked ${++count}x`);
|
||||
};
|
||||
|
||||
if (!('name' in this.dataset)) {
|
||||
this.dataset.name = 'World'
|
||||
}
|
||||
|
||||
this.onclick = () => this.dataset.name = `Clicked ${++count}x`;
|
||||
}
|
||||
|
||||
attributeChangedCallback(property, previousValue, currentValue) {
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
<code-block>npm create <strong style="color: var(--color-blue)">mcfly</strong>@latest</code-block>
|
||||
<p>
|
||||
Here's a sample interactive custom element:
|
||||
<vanilla-hello-world data-name="McFly"></vanilla-hello-world>
|
||||
<vanilla-hello-world></vanilla-hello-world>
|
||||
</p>
|
||||
<p>
|
||||
Start at the very basic of writing HTML files and enhance with
|
||||
|
|
|
@ -5,9 +5,12 @@ class HelloWorld extends HTMLElement {
|
|||
|
||||
connectedCallback() {
|
||||
let count = 0;
|
||||
this.onclick = () => {
|
||||
this.setAttribute("data-name", `Clicked ${++count}x`);
|
||||
};
|
||||
|
||||
if (!('name' in this.dataset)) {
|
||||
this.dataset.name = 'World'
|
||||
}
|
||||
|
||||
this.onclick = () => this.dataset.name = `Clicked ${++count}x`;
|
||||
}
|
||||
|
||||
attributeChangedCallback(property, previousValue, currentValue) {
|
||||
|
|
|
@ -25,8 +25,7 @@
|
|||
<main>
|
||||
<h2>Welcome to {{ project.name }}</h2>
|
||||
<p>
|
||||
Here's a vanilla custom element:
|
||||
<vanilla-hello-world data-name="{{project.name}}" />
|
||||
Here's a vanilla custom element: <vanilla-hello-world/>
|
||||
</p>
|
||||
<code-block language="js">
|
||||
class HelloWorld extends HTMLElement {
|
||||
|
|
Loading…
Reference in a new issue