<!doctype html>
<my-counter></my-counter>
<script type="module">
import { html, component, useState, useEffect } from 'https://unpkg.com/haunted/haunted.js';
function Counter() {
const [count, setCount] = useState(0);
useEffect(() => {
document.title = `Clicked ${count} times`;
});
return html`
<div id="count">${count}</div>
<button type="button" @click=${() => setCount(count + 1)}>Increment</button>
`;
}
customElements.define('my-counter', component(Counter));
</script>
我猜 不久的将来,UI库都会用 Web Components来写,那么,不再区分vue, react, Svelte ... ui专注ui,库专注业务