我有一个自定义组件<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>
但是,我得到了这个错误
calcs未捕获ReferenceError: AppList未在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。
谢谢!
https://stackoverflow.com/questions/50726718
复制相似问题