看源码的时候看到这个属性:

新手自然不知道这个是什么东西了,查了下vue  API:

https://router.vuejs.org/en/advanced/scroll-behavior.html

上面这个的意思就是当转到一个新的页面时,定位到最顶端。

Scroll Behavior

When using client-side routing, we may want to scroll to top when navigating to a new route, or preserve the scrolling position of history entries just like real page reload does. vue-router allows you to achieve these and even better, allows you to completely customize the scroll behavior on route navigation.

Note: this feature only works in HTML5 history mode.

When creating the router instance, you can provide the scrollBehavior function:

const router = new VueRouter({
routes: [...],
scrollBehavior (to, from, savedPosition) {
// return desired position
}
})

The scrollBehavior function receives the to and from route objects. The third argument, savedPosition, is only available if this is a popstatenavigation (triggered by the browser's back/forward buttons).

The function can return a scroll position object. The object could be in the form of:

  • { x: number, y: number }
  • { selector: string }

If a falsy value or an empty object is returned, no scrolling will happen.

For example:

scrollBehavior (to, from, savedPosition) {
return { x: 0, y: 0 }
}

This will simply make the page scroll to top for all route navigations.

Returning the savedPosition will result in a native-like behavior when navigating with back/forward buttons:

scrollBehavior (to, from, savedPosition) {
if (savedPosition) {
return savedPosition
} else {
return { x: 0, y: 0 }
}
}

If you want to simulate the "scroll to anchor" behavior:

scrollBehavior (to, from, savedPosition) {
if (to.hash) {
return {
selector: to.hash
}
}
}

We can also use route meta fields to implement fine-grained scroll behavior control. Check out a full example here.

vue2路由之指定滑动位置scrollBehavior-(载转)的更多相关文章

  1. vue2路由之指定滑动位置scrollBehavior

    看源码的时候看到这个属性: 新手自然不知道这个是什么东西了,查了下vue  API: https://router.vuejs.org/en/advanced/scroll-behavior.html ...

  2. json解析,异步下载(listview仅滑动时加载)Demo总结

    异步加载的练习demo 主要涉及知识点: 1.解析json格式数据,主要包括图片,文本 2.使用AsynTask异步方式从网络下载图片 3.BaseAdapter的"优雅"使用 4 ...

  3. JS控制div跳转到指定的位置的解决方案总结

    总结一下自己在写这个需求遇到的问题,相信大家应该是经常遇到的.即要求滚轮滚动到指定的位置.先看下基本的解决方案. 1.给链接a加个#的方式来实现跳转.(锚点方法)这里直接贴下代码: html页面: & ...

  4. express框架路由配置及congtroller自动加载

    express框架在node官方推荐的一个框架,关于如何入门的文章,已经很多了,我就不在累赘了,本文的核心是如何修改文件使得更接近一个MVC的框架 express原生是通过require的方式实现了模 ...

  5. springboot打包去除资源文件,启动时指定配置文件位置,使用log4j2替换默认logback

    springboot打包时,去掉资源文件 <build> <resources> <resource> <directory>src/main/reso ...

  6. JS控制div跳转到指定的位置的几种解决方案总结

    原文:http://www.jb51.net/article/96574.htm 这篇文章主要介绍了JS控制div跳转到指定的位置的几种解决方案总结,小编觉得挺不错的,现在分享给大家,也给大家做个参考 ...

  7. Android RecyclerView使用 及 滑动时加载图片优化方案

    1.控制线程数量 + 数据分页加载2.重写onScrollStateChanged方法 这个我们后面再谈,下面先来看看RecyclerView控件的使用及我们为什么选择使用它 RecyclerView ...

  8. [Android Pro] 精确记录和恢复ListView滑动位置

    reference to : http://blog.csdn.net/welovesunflower/article/details/7926512 工作中遇到一个需求,对ListView某一项操作 ...

  9. VS2013编译经常卡在正在从以下位置加载xxx.dll的符号

    换了系统后,重新下载了一个vs2013 with update2安装,编译的时候总是卡在 正在从以下位置加载xxx.dll的符号 如图: 解决方法: 进入VS---工具---选项----调试----符 ...

随机推荐

  1. GAMES101作业2

    作业任务: 填写并调用函数 rasterize_triangle(const Triangle& t). 即实现光栅化 该函数的内部工作流程如下: 创建三角形的 2 维 bounding bo ...

  2. 记一次metasploitable2内网渗透之21,22,23,25端口爆破

    Hydra是一款非常强大的暴力破解工具,它是由著名的黑客组织THC开发的一款开源暴力破解工具.Hydra是一个验证性质的工具,主要目的是:展示安全研究人员从远程获取一个系统认证权限. 目前该工具支持以 ...

  3. Horovod-Usage

    Usage 代码中要包含以下6步: 初始化 Run hvd.init() to initialize Horovod. 将每个GPU固定到单个进程以避免资源争用. 一个线程一个GPU,设置到 loca ...

  4. BLE广播信道空中包详解

    广播信道空中包 在学习BLE的过程中,对于广播信道的空中包有许多混淆的地方,包括各个空中包的用途,帧格式等.现在想把他们做一个总结和归纳. BLE广播信道中的空中包分为有以下几种: 可连接非定向广播 ...

  5. 逻辑引擎、工作流、CMDB小感

    工作流是啥? 在界面上画画点点就能生成代码,这是很吸引人的事情,也是很多自动化工具追求的目标.工作流就是这么一个东西,通过定义流程和输入,就能实现你想要的东西,不需要编写代码. 工作流的实现 通过解析 ...

  6. 03- HTML基本结构

    初始HTML HTML(英文Hyper Text Markup Language的缩写)中文译为"超文本标签语言",主要是通过HTML标签对网页中的文本.图片.声音等内容进行描述. ...

  7. 去css 冗余方法

    1.float在某种意义上而言与display:inline-block属性的作用是一模一样的, 所以类似于display:block; float:left; 就是说.float:left 可以让行 ...

  8. Ubuntu20安装Truffle框架并部署第一个DApp

    1.查看Ubuntu版本信息 $ screenfetch 2.安装node ①查看nodejs官网稳定版(LTS)版本号(下面的14就是此时的版本号) ②添加源 $ curl -sL https:// ...

  9. Win64 驱动内核编程-31.枚举与删除映像回调

    枚举与删除映像回调 映像回调可以拦截 RING3 和 RING0 的映像加载.某些游戏保护会用此来拦截黑名单中的驱动加载,比如 XUETR.WIN64AST 的驱动.同理,在反游戏保护的过程中,也可以 ...

  10. MetInfo Password Reset Poisoning By Host Header Attack

    if we know some user's email, the we will can reset the user's email by host header attack. The atta ...