【发布时间】:2017-12-08 13:17:32
【问题描述】:
我正在尝试创建新的自定义元素。
我有一个非常简单的 html 索引文件:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="dist/webcomponents-lite.js"></script>
</head>
<body>
<h1>WebComponents</h1>
<hello-world></hello-world>
<script src="src/components/hello-world.js"></script>
</body>
</html>
我的 hello-world 组件如下:
class HelloWorldElement extends HTMLElement {
constructor(){
super()
this.innerHTML = `<h1>Hello Meetup !</h1>`;
}
connectedCallback(){
console.log("I'm here!");
}
disconnectedCallback(){
console.log("I'm gone!");
}
}
window.customElements.define(
'hello-world',
HelloWorldElement);
这段代码 sn-p 在 Chrome 和 Safari 中运行良好。
我添加了 webcomponents-lite.js 导入以添加对其他浏览器的支持。
但是,当尝试在 Firefox 中运行代码时,出现以下错误:
too much recursion
[Learn More]
webcomponents-lite.js:93:170
我在网上找到的关于可能发生的事情的信息非常少。
我想我正在遵循 Web 组件网站的 polyfills page 中解释的推荐路径。
知道发生了什么吗?
谢谢
编辑:
我可以通过在 firefox 配置中启用 dom.webcomponents.customelements.enabled 和 dom.webcomponents.enabled 并删除 polyfill 来显示自定义元素,但这显然不是生产所需要的。
【问题讨论】:
-
我还看到其他网站(例如 component.kitchen/tutorial)在 Firefox 中运行良好,所以上面的 HTML 肯定有问题
标签: javascript html firefox web-component custom-element