Single file Web Component
October 27, 2021 ยท View on GitHub
<h1>Hello World</h1>
<script type=module>
class HelloWorld extends HTMLElement {
constructor () {
super()
const template = document.getElementById('single-file')
this.attachShadow({ mode: 'open' })
.appendChild(template.content.cloneNode(true))
}
connectedCallback () {
console.log('Why hello there ๐')
}
}
customElements.define('hello-world', HelloWorld)
</script>