vue 路由对象属性 比眉伴天荒 2021-07-24 15:41 368阅读 0赞 [更多路由属性查看官网][Link 1] this.$route.path 类型: string 字符串,对应当前路由的路径,总是解析为绝对路径,如 "/foo/bar"。 this.$route.params 类型: Object 一个 key/value 对象,包含了动态片段和全匹配片段,如果没有路由参数,就是一个空对象。 this.$route.query 类型: Object 一个 key/value 对象,表示 URL 查询参数。例如,对于路径 /foo?user=1,则有 this.$route.query.user == 1,如果没有查询参数,则是个空对象。 this.$route.hash 类型: string 当前路由的 hash 值 (带 #) ,如果没有 hash 值,则为空字符串。 this.$route.fullPath 类型: string 完成解析后的 URL,包含查询参数和 hash 的完整路径。 this.$route.matched 类型: Array<RouteRecord> 一个数组,包含当前路由的所有嵌套路径片段的路由记录 。路由记录就是 routes 配置数组中的对象副本 (还有在 children 数组)。 const router = new VueRouter({ routes: [ // 下面的对象就是路由记录 { path: '/foo', component: Foo, children: [ // 这也是个路由记录 { path: 'bar', component: Bar } ] } ] }) 当 URL 为 /foo/bar,$route.matched 将会是一个包含从上到下的所有对象 (副本)。 this.$route.name 当前路由的名称,如果有的话。(查看命名路由) $route.redirectedFrom 如果存在重定向,即为重定向来源的路由的名字。(参阅重定向和别名) # 组件注入 [Link 1]: https://router.vuejs.org/zh/api/#%E8%B7%AF%E7%94%B1%E5%AF%B9%E8%B1%A1
还没有评论,来说两句吧...