传参 this.$route.push({path:'/xxx',query:{id:1}});//类似get传参,通过URL传递参数
this.$route.push({path:'/xxx',params:{id:1}});//类似post传参
接收参数 this.$route.query.id
this.$route.params.id
路径参数使用冒号 : 标记。当匹配到一个路由时,参数值会被设置到 this.$route.params,可以在每个组件内使用。 const router = new VueRouter({
routes: [
// 动态路径参数 以冒号开头
{ path: '/user/:id', component: User }
]
})
接收: const User = {
template: '<div>User {{ $route.params.id }}</div>'
}
参考:https://router./zh-cn/essentials/dynamic-matching.html
|