项目时vue+ts,导航栏是一个组件,其中有个多级子菜单点击要实现某个菜单锚点跳转,怎么搞?
网上都说可以这样
private jumpTo(path: ""): void {
if (document.querySelector("#" + path))
<HTMLElement>document.querySelector("#" + path).scrollIntoView(true);
}
但获取dom这条语句错误!关于ts操作dom我也一直没弄明白,我该从哪里了解这方面知识呢?
document.querySelector
在 TS 看来可能返回值为null
,你需要加下非空断言操作符: