傳統的錨點定位會與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(); } } }