Dynamic Route Matching Vue路由(1)
Dynamic Route Matching
动态的 路由 匹配
Very often we will need to map routes with the given pattern to the same component. For example we may have a User component which should be rendered for all users but with different user IDs. In vue-router we can use a dynamic segment in the path to achieve that:
需要通过给定的模式去导航路由到相同的模块,比如我们有一个用户组件,它被每个用户所使用,但是每个用户有不同的id。在vue 路由中,我们可以使用一个动态的部分 来实现它。
const User = {
template: '<div>User</div>'
}
const router = new VueRouter({
routes: [
// dynamic segments start with a colon
{ path: '/user/:id', component: User }
]
})
Now URLs like /user/foo and /user/bar will both map to the same route.
现在 像/user/foo 和 /user/bar 的URLS 将被同时导航到 相同的 地方
A dynamic segment is denoted by a colon :. When a route is matched, the value of the dynamic segments will be exposed as this.$route.params in every component. Therefore, we can render the current user ID by updating User's template to this:
一个动态的部分被: 标志, 当一个路由相匹配时,动态变量的值将会被暴露为this.$route.params,在每一个组件里。因此,我们可以填充当前的用户id通过更新用户组件成这样:
const User = {
template: '<div>User {{ $route.params.id }}</div>'
}
You can have multiple dynamic segments in the same route, and they will map to corresponding fields on $route.params. Examples:
你可以有很多多样的的动态变量在同一个路由里面,他们将映射到对应的部分,在$route.params
|
In addition to $route.params, the $route object also exposes other useful information such as $route.query (if there is a query in the URL), $route.hash.etc. You can check out the full details in the API Reference
除了 $route.params, $route 对象还暴露出其他的有用信息,比如 路由?,路由的哈希,等等。你可以查询所有的细节在api参考里。
Dynamic Route Matching Vue路由(1)的更多相关文章
- Vue路由vue-router
前面的话 在Web开发中,路由是指根据URL分配到对应的处理程序.对于大多数单页面应用,都推荐使用官方支持的vue-router.Vue-router通过管理URL,实现URL和组件的对应,以及通过U ...
- Vue 路由详解
Vue 路由详解 对于前端来说,其实浏览器配合超级连接就很好的实现了路由功能.但是对于单页面应用来说,浏览器和超级连接的跳转方式已经不能适用,所以各大框架纷纷给出了单页面应用的解决路由跳转的方案. V ...
- Vue路由-详细总结
Vue路由vue-router 前面的话 在Web开发中,路由是指根据URL分配到对应的处理程序.对于大多数单页面应用,都推荐使用官方支持的vue-router.Vue-router通过管理URL ...
- Vue路由Hash模式分析
Vue路由Hash模式分析 Vue-router是Vue的核心组件,主要是作为Vue的路由管理器,Vue-router默认hash模式,即使用URL的Hash来模拟一个完整的URL,当URL改变时页面 ...
- Vue路由History模式分析
Vue路由History模式分析 Vue-router是Vue的核心组件,主要是作为Vue的路由管理器,Vue-router默认hash模式,通过引入Vue-router对象模块时配置mode属性可以 ...
- Vue路由学习心得
GoodBoy and GoodGirl~进来了就看完点个赞再离开,写了这么多也不容易的~ 一.介绍 1.概念:路由其实就是指向的意思,当我们点击home按钮时,页面中就要显示home的内容,点击l ...
- vue路由原理剖析
单页面应用(SPA)的核心之一是: 更新视图而不重新请求页面, 实现这一点主要是两种方式: 1.Hash: 通过改变hash值 2.History: 利用history对象新特性(详情可出门左拐见: ...
- vue路由vue-router的使用
对于单页应用,官方提供了vue-router进行路由跳转的处理. 安装 基于传统,我更喜欢采用npm包的形式进行安装. npm install vue-router --save 当然,官方采用了多种 ...
- 3种vue路由传参的基本模式
路由是连接各个页面的桥梁,而参数在其中扮演者异常重要的角色,在一定意义上,决定着两座桥梁是否能够连接成功. 在vue路由中,支持3中传参方式. 场景,点击父组件的li元素跳转到子组件中,并携带参数,便 ...
随机推荐
- 新闻网大数据实时分析可视化系统项目——11、MySQL安装
1.修改yum源 鉴于用国外的Yum源,速度比较慢,所以想到将国外的yum源改为国内的Yum源,这里选择使用比较多的阿里云源.具体修改方法可以参考此连接 2.在线安装mysql 通过yum在线mysq ...
- @Controller 和 @RestController 的区别
@Controller和@RestController的区别? 官方文档:@RestController is a stereotype annotation that combines @Respo ...
- 二十四 Redis消息订阅&事务&持久化
Redis数据类型: Redis控制5种数据类型:String,list,hash,set,sorted-set 添加数据,删除数据,获取数据,查看有多少个元素,判断元素是否存在 key通用操作 JR ...
- 项目实战报异常Exception及决绝方案
1.报LifecycleException,再配置一下jdk即可,然后再手动添加maven 解决方法: 然后,手动添加jar包 2.maven 项目,右键maven build启动项目的时候,报下面 ...
- PV 动态供给【转】
前面的例子中,我们提前创建了 PV,然后通过 PVC 申请 PV 并在 Pod 中使用,这种方式叫做静态供给(Static Provision). 与之对应的是动态供给(Dynamical Provi ...
- 图像检索:CEDD(Color and Edge Directivity Descriptor)算法 颜色和边缘的方向性描述符
颜色和边缘的方向性描述符(Color and Edge Directivity Descriptor,CEDD) 本文节选自论文<Android手机上图像分类技术的研究>. CEDD具有抽 ...
- 爬虫(十六):Scrapy框架(三) Spider Middleware、Item Pipeline
1. Spider Middleware Spider Middleware是介入到Scrapy的Spider处理机制的钩子框架. 当Downloader生成Response之后,Response会被 ...
- git commit -m 和 git commit -am 区别
git commit -m 和 git commit -am 通常修改一个文件 并且将文件提交到本地分支的命令是: git add . git commit -m 'update' 以上两个命令其实可 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-music
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- Linux netfliter 架构
netfliter 简介 netfilter是在Linux 2.4.X内核引入的一个子系统,它提供了一个抽象的.通用框架,这个框架提供了一整套的钩子函数的管理机制.包括钩子函数的原型定义,注册,注销等 ...