方法一:
html:
<a href="#service">点击跳转到定位处</a>
<div id="service">定位处</div>
可能需要自己移除一下a标签的默认事件。
方法二:
html:
<button @click="toService">点击跳转到定位处</button>
<div id="service">定位处</div>
js:
toService() {
document.documentElement.scrollTop =
document.querySelector("#service").offsetTop - 100;
},
结尾的
-100
是调整位置,可不写。