为什么 v1 Web 组件 customElements.define() 会抛出 TypeError

2024-03-23

我正在使用 v1 Web 组件。根据埃里克·比德尔曼 (Eric Bidelman) 的说法自定义元素 v1:可重用的 Web 组件 https://developers.google.com/web/fundamentals/primers/customelements/,可以使用以下命令定义和创建 v1 Web 组件:

class App extends HTMLElement {

  attachedCallback() {
    this.attachShadow({mode: 'open'});
    this.shadowRoot.innterHTML = `<div>web component</div>`

  }
}

and

<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 代码。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么 v1 Web 组件 customElements.define() 会抛出 TypeError 的相关文章

随机推荐