【发布时间】:2018-06-06 17:56:51
【问题描述】:
我有一个自定义 Web 组件 <app-list>,我正在尝试将其扩展到 <calcs-list>。
// app-list.html
<script>
window.customElements.define('app-list',
class AppList extends HTMLElement {
constructor() {
super();
}
}
);
</script>
在 calcs-list.html 我有:
<link rel="import" href="app-list.html">
<script>
window.customElements.define('calcs-list',
class CalcsList extends AppList {
constructor() {
super();
console.log('CalcsList constructed');
}
}
);
</script>
但是,我得到了错误
Uncaught ReferenceError: AppList is not defined at calcs-list.html:11
第 11 行引用 class CalcsList extends AppList {
这两个文件是同一个文件夹的同级文件。我在将app-list.html 导入calcs-list.html 时尝试使用绝对路径,但得到了相同的结果。
我还尝试将这两个组件导入到我的主 index.html 文件中:
//index.html
<link rel="import" href="/src/components/app-list.html">
<link rel="import" href="/src/components/calcs-list.html">
<app-list></app-list>
<calcs-list></calcs-list>
但体验相同的结果。
app-list 组件在我的应用程序中运行没有任何问题。
我在这个问题上摸不着头脑,因为 Web 组件是相当新的东西,在线上没有很多故障排除信息,尤其是在 Web 组件 V1 中。
谢谢!
【问题讨论】:
标签: web-component extends custom-element native-web-component