【发布时间】:2023-03-28 05:25:02
【问题描述】:
尝试使用 webcomponents,但遇到了一个我没有得到的错误。
标记很简单,应该可以工作。 2个文件,都是html文件。
错误标记在控制台的<script> 标记上。
感谢您的帮助。
PS。我正在运行 Google Chrome Beta 以使 customElements 工作。
km-button.html
<script>
class KmButton extends HTMLButtonElement {
constructor() {
super();
}
}
customElements.define('km-button', KmButton, {extends: 'button'});
</script>
index.html
<!DOCTYPE html>
<html>
<head>
<!-- import webcomponents -->
<link rel="import" href="./components/km-button.html">
</head>
<body>
<km-button>hej</km-button>
</body>
</html>
错误
km-button.html:1 Uncaught TypeError: Illegal constructor(…)KmButton @ km-button.html:7
【问题讨论】:
标签: javascript html web-component custom-element