方式一:this.$router.push({name:"name",params:{}"})
{
path: '/home',
name: 'Home',
component: Home
}
this.$router.push({
name:"Home",
params:{
id:"11111"
}
})
this.$route.params.id
方式二:this.$router.push({path:"path",query:{}"})
{
path: '/home',
name: 'Home',
component: Home
}
this.$router.push({
path:"/home",
query:{
id:"11111"
}
})
this.$route.query.id
方式三:
{
path: '/home/:id',
name: 'Home',
component: Home
}
this.$router.push({
path: `/home/${id}`,
})
this.$route.query.id
- 方式一传参时,参数不会显示在浏览器地址栏,方式二和方式三都会显示在浏览器地址栏。
- 方式一传参时,浏览器刷新后值会消失,方式二三则不会。