尝试使用 webcomponents 但遇到了一个我没有得到的错误。
标记很简单,应该可以工作。 2个文件,都是html文件。
错误标记在 <script>
上在控制台中标记。
感谢您的帮助。
附言。我正在运行 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
最佳答案
实际上它仍然不起作用(在您更正之后)。
据我所知extends
Chrome 的自定义元素 v1 中尚未实现此功能。
所以 is=
语法被简单地(默默地)忽略,您的按钮被视为标准 <button>
.
关于javascript - Webcomponents v1 - 非法构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39625876/