Vue的路由对象

栏目: JavaScript · 发布时间: 6年前

内容简介:1. 一个路由对象(route object)表示当前激活的路由的状态信息,包含了当前URL解析得到的信息,还有URL匹配到的路由记录(route records)。

1. 一个路由对象(route object)表示当前激活的路由的状态信息,包含了当前URL解析得到的信息,还有URL匹配到的路由记录(route records)。

2. 路由对象是不可变的,每次成功的导航都会产生一个新的对象。

3. 路由出现的地方有以下几个(慢慢熟悉):

  • 在组件内,即this.$route;
  • 在$route观察者回调内;
  • router.match(location)的返回值;
  • 导航守卫的参数:

    router.beforeEach((to, from, next) => {
               // to 和 from 都是路由对象
           })
  • scrollBehavior方法的参数:

    const router = new VueRouter({
               scrollBehavior (to, from, savedPosition){
                   // to 和 from 都是路由对象
               }
           })

4.路由对象属性:

  • $router.path string类型,对应当前路由的路径,总是解析为绝对路径,如"/man/tom"
  • $router.params object类型,一个key/value对象,包含了动态片段和全匹配片段,如果没有路由参数,就是空对象
  • $router.query object类型,一个key/value对象,表示URL查询参数。例如,对于路径 /
  • 列表项目
  • 列表项目
  • 列表项目
  • 列表项目

以上所述就是小编给大家介绍的《Vue的路由对象》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Web Security Testing Cookbook

Web Security Testing Cookbook

Paco Hope、Ben Walther / O'Reilly Media / 2008-10-24 / USD 39.99

Among the tests you perform on web applications, security testing is perhaps the most important, yet it's often the most neglected. The recipes in the Web Security Testing Cookbook demonstrate how dev......一起来看看 《Web Security Testing Cookbook》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具