我正在處理導航鏈接Web組件。我想在組件上設置的其中一個屬性是標題。這似乎是以某種方式觸發最大的callstack錯誤。我應該完全避免title
?我可以用caption
代替。將標題設置爲Web組件上的屬性觸發最大呼叫堆棧
第一個錯誤
Class 'NavLinkCmp' incorrectly extends base class 'HTMLElement'. Property 'title' is private in type 'NavLinkCmp' but not in type 'HTMLElement'.
二錯誤
nav-link.cmp.ts:72 Uncaught RangeError: Maximum call stack size exceeded.
at HTMLElement.attributeChangedCallback (nav-link.cmp.ts:72)
導航,cmp.ts
<nav-link-cmp href="${link.url}" fa-icon="${link.icon}"
title="${link.title}" description="${link.description}">
</nav-link-cmp>
NAV-鏈路cmp.ts
export class NavLinkCmp extends HTMLElement {
// State
private title: string;
constructor() {
super();
}
connectedCallback() {
this.render();
}
render() {
this.innerHTML = `
<div class="info">
<div class="title">${this.title}</div>
</div>
`;
}
static get observedAttributes() {
return ['title'];
}
attributeChangedCallback(name: string, oldValue: string, newValue: string) {
this.title = newValue
}
}
// Component
require('./nav-link.cmp.scss');
window.customElements.define('nav-link-cmp', NavLinkCmp);
也許刪除私人? – nlgn
我不得不添加它,因爲第一個錯誤 –