fix: 空值异常

This commit is contained in:
禾几海
2020-10-10 00:25:22 +08:00
parent b63697f717
commit a4fa38deee
3 changed files with 6 additions and 10 deletions

View File

@@ -73,9 +73,8 @@ export class ArticleComponent implements OnInit {
after: () => {
// 处理锚点
const tocList: HTMLCollection = this.divElement.nativeElement
.getElementsByClassName('vditor-toc')[0]
.getElementsByTagName(`a`);
for (let i = 0; i < tocList.length; i++) {
.getElementsByClassName('vditor-toc')[0]?.getElementsByTagName(`a`);
for (let i = 0; i < tocList?.length; i++) {
const linkValue = tocList.item(i).getAttribute('href');
tocList.item(i).setAttribute('href', window.location.pathname + linkValue);
}