0
点赞
收藏
分享

微信扫一扫

Vue路由跳转页面后-新页面没有位于顶部-案例



页面通过路由调转后,新页面停留的位置与上一级页面一致


解决


配置路由


const router = new VueRouter({
scrollBehavior: () => ({ y: 0 }),
routes: [...]
})

// 可能是使用组件缓存时 再次切换到此组件 路由不触发mounted钩子函数

原生js操作

toYpWebsite () {
// this.$router.push('/ypWebsite')
document.body.scrollTop = document.documentElement.scrollTop = 0;
}


举报

相关推荐

0 条评论