window.customElements.define('xx-xxx', ComponentName)
&class ComponentName extends HTMLElement{}
<template></template>
- document.getElementByTagName(‘template’).content.cloneNode(true)
<style> :host{}</style>
:host伪类,指代自定义元素本身。<user-card image="urlxxx"></user-card>
& class ComponentName中:this.getAttribute('image')
- class 内部
this.attachShadow( { mode: 'closed' } );
开启Shadow DOM
,将组件内部代码隐藏起来 不允许外部访问
http://www.ruanyifeng.com/blog/2019/08/web_components.html
https://github.com/ionic-team/stencil
Web Component 和类 vue 组件化技术谁会成为未来?
相关文章:vite 通过web import
不幸的是,「规范」永远都是
落后保守的。不论是功能覆盖、API 设计还是可塑性。作为「规范」,这种取舍也是正确的。对于 Web 组件话方案而言,从 Angular、React 和 Vue 中任选一个,都能获得比「规范」所提供的方案更多的功能、更快的反馈周期和更高的自主性。所以,在同样需要 Compilation 和 Polyfill 的情况下,何乐而不为呢?