路由传参的三种方式(query/params) |
您所在的位置:网站首页 › 电脑装机的几种方式 › 路由传参的三种方式(query/params) |
路由带参数: 传参方式可划分为 params 传参和 query 传参,而 params 传参又可分为在 url 中显示参数和不显示参数两种方式 1.params 传参(显示参数)又可分为 声明式 和 编程式 两种方式 声明式router-link:该方式是通过router-link组件的to属性实现,子路由需要提前配置好参数。 跳转到子路由 { path: '/child/:id', component: Child } 编程式 this.$router.push:同样需要子路由提前配置好参数。 { path: '/child/:id', component: Child } this.$router.push({ path:'/child/${id}', })接收: this.$route.params.id 2. params传参(不显示参数)也可分为声明式和编程式两种方式,与显示参数不同的是,这里是通过路由的别名 name 进行传值的 跳转到子路由 { path: '/child, name: 'Child', component: Child } this.$router.push({ name:'Child', params:{ id:1 } })接收: this.$route.params.id 3.query 传参(显示参数)也可分为声明式和编程式 两种方式 声明式router-link:该方式是通过 router-link 组件的 to 属性实现,不过使用该方式传值的时候,需要子路由提前配置好路由别名 { path: '/child, name: 'Child', component: Child } 跳转到子路由 编程式 this.$router.push:使用该方式传值的时候,同样需要子路由提前配置好路由别名(name 属性) { path: '/child, name: 'Child', component: Child } this.$router.push({ name:'Child', query:{ id:1 } })接收: this.$route.query.id |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |