Vue 导航栏 实现从其他页面跳到新页面板块内容下
methods:{
jumpPage() {
//跳转锚节点
var hash = window.location.hash;
// 获取 url 的 # 结束的位置
var index = hash.lastIndexOf("#");
// 获取 以 # 位置到最后的位置锚点
var id = hash.substring(index + 1, hash.length + 1);
var div = document.getElementById(id);
if (index != -1) {
setTimeout(() => {
div.scrollIntoView(true);
}, 200)
}
}
},
watch: {
$route(to, from) {
this.turnAuchor();
this.menuOpen = false;
},
},
本文介绍了一种Vue.js应用中实现从当前页面平滑跳转到特定锚点的方法。通过监听路由变化并延迟滚动到目标元素的方式,提高了用户体验。
1282

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



