您现在的位置是: 首页 > 前端开发 Vue 路由跳转后不在顶部
Vue 路由跳转后不在顶部
2020-09-03 【前端开发】 1432人已围观 2383次浏览
简介Vue 路由跳转后不在顶部
Vue 项目中,在很长的页面中,使用下面代码
this.$router.push('/post/1')
进行路由跳转时,就会出现滚动条还是在当前位置,跳转的目标页并没有在顶部的问题,这样会对于很多长页面来说,是很困扰的
比较简单的解决方法就就是在 Vue 项目的 main.js 中添加下面的代码
// 处理页面跳转后不在顶部问题
router.afterEach((to, from, next) => {
window.scrollTo(0, 0)
})
具体位置可以是在 new Vue({ 之前即可,放在文件最后可能会出现不生效的问题
保存之后,再点击跳转,就会默认跳转目标页顶部
很赞哦! (0)
点击排行
- Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: ERR DISABLE You can't write or read against a disable instance
- RocketMQ 出现 sendDefaultImpl call timeout 问题
- Debian apt 使用国内镜像
- 类 BASE64Decoder 程序包 sun.misc 找不到符号
- SpringBoot @NotBlank 不生效问题
- 记一次 Mybatis-Plus 自动填充无效问题解决
- nuxt 项目完整部署方案
- SpringBoot 2.x 文件上传出现 The field file exceeds its maximum permitted size of 1048576 bytes
站长推荐
猜你喜欢
- Windows CMD 常用命令
- SpringBoot 启动提示 Requested bean is currently in creation: Is there an unresolvable circular reference?
- layUI点击按钮页面刷新问题解决方案
- Vue 路由跳转后不在顶部
- mac idea spring boot 启动慢
- 解决Lost connection to MySQL server at 'reading initial communication packet' 的方法
- 使用 OpenSSL 将 pfx 格式证书转为 pem 格式
- PHP 中list()出现Undefined offset: 0错误
- sentinel directive while not in sentinel mode 问题解决
- CentOS 安装Node.js