解决vue路由与锚点冲突

传统的锚点定位会与vue-router中的路由设置存在冲突,解决方法自定义锚点跳转:

html: 

<ul>
  <li><a href="" @click.prevent="custormAnchor('firstAnchor')">公共报文头</a></li>    
</ul>

 js: 

methods: {
    custormAnchor(anchorName) {
        // 找到锚点
        let anchorElement = document.getElementById(anchorName);
        // 如果对应id的锚点存在,就跳转到锚点
        if(anchorElement) { anchorElement.scrollIntoView(); }
    }
}

 

posted @ 2017-12-04 15:05  奔跑的蜗牛~  阅读(7724)  评论(0编辑  收藏  举报