javascript - 为什么 v1 web 组件 customElements.define() 抛出 TypeError

标签 javascript web-component

我正在玩弄 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/

相关文章:

javascript - 我遇到了 Handlebars 问题( Handlebars 未定义)

javascript - 本地存储javascript变量到php

javascript - 我们需要在自定义元素的 adoptedCallback 中做什么?

javascript - 在 Polymer Web 组件中使用 AngularJS

javascript - 如何将变量传递到我的脚本 .js 文件?

javascript - Mongoose 在将一个文档保存到数据库后产生冲突

javascript - 如何自定义颜色tailwind css上的直通文本装饰

css - 具有 Web 组件的应用程序的全局 CSS

internet-explorer - Web 组件、HTML 导入 polyfill 在 Firefox、IE 中不起作用

ecmascript-6 - 如何为 Polymer 2 创建自定义元素 "resize"mixin?