解決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(); }
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM