首先在指定的位置增加一个锚点(要被跳转的页面)
<div id='main'></div>
我们要跳转的时候,其实在路由后面拼接一个#main 就可以了
下面是没有锚点,要准备点击后跳转的页面
<div class="" @click="goTo('/Market#market')">每日价格</div>
goTo(path) {
window.open(path, "_blank");
},
然后在被跳转的页面增加一下代码
也就是有锚点的页面:
mounted() {
const hash = this.$route.hash;
if (hash) {
const position = document.getElementById(hash.substring(1));
if (position ) {
position .scrollIntoView();
}
}
},
文章讲述了如何在Vue.js应用中使用锚点进行页面跳转,并在目标页面自动滚动到相应位置。首先,通过在URL后面添加#和锚点ID实现无锚点页面的跳转。接着,在有锚点的页面上,利用Vue的$route.hash属性获取并滚动到指定位置。
&spm=1001.2101.3001.5002&articleId=134704357&d=1&t=3&u=64c872e783a54515b23e25c1f7d9f3a2)
1707

被折叠的 条评论
为什么被折叠?



