我正在玩弄 v1 网络组件。根据 Eric Bidelman 在 Custom elements v1: reusable web components 中的说法,一个 v1 网络组件可以定义和创建:
class App extends HTMLElement {
attachedCallback() {
this.attachShadow({mode: 'open'});
this.shadowRoot.innterHTML = `<div>web component</div>`
}
}
和
<x-app></x-app>
但是,在最新版本的 Chrome Canary 中运行代码并在 Firefox 中使用 v1 polyfill 时,会抛出以下错误:
Uncaught TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
最佳答案
如果您转译 es6 代码,则需要包含来自 webcomponents/src/CustomElements/vs 的 native-shim.js 代码。
关于javascript - 为什么 v1 web 组件 customElements.define() 抛出 TypeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39477678/