方法一
this.$router.push({
path:`/home/${id}`,
})
路由配置
{
path:"/home/:id",
name:"Home",
component:Home
}
在Home組件中獲取參數值
this.$route.params.id
方法二
通過name來匹配路由,通過param來傳遞參數
this.$router.push({
name:'Home',
params:{
id:id
}
})
用params傳遞參數,不使用:/id
{
path:'/home',
name:Home,
component:Home
}
Home組件中獲取參數
this.$route.params.id
方法三
path+query;query傳遞的參數會通過?id = xxx展示
this.$router.push({
path:'/home',
query:{
id:id
}
})
路由配置
{
path:'/home',
name:Home,
component:Home
}
獲取參數的方法
this.$route.query.id