1. router-link
1.不带参数
<router-link :to="{path:'/home'}" />
2.带参数
//路由里面配置path:"/home/:id" 或者 path:"/home:id"
//html取参 $route.params.id
//script 取参 this.$route.params.id
<router-link :to="{name:'home',params:{id:1}}" />
2. this.$router.push()
//基于name配置路由
this.$router.push({name:'home',query:{id:1,age:2}})
//路由里面的写法
{
path: '/hhhhhhh', //这里可以任意
name: 'home', //这里必须是home
component: Home
}
//----------------------------------------------------------------------------
//基于path配置路由
this.$router.push({path:'/home',query:{id:1,age:2}})
//路由里面的写法
{
path: '/home', //这里必须是home
name: 'home', //这里任意
component: Home
}
3. params
通过路由属性中的name匹配路由,再根据params传递参数
父组件: 匹配路由配置好的属性名