1. push方法
1. 参数会在地址栏显示
this.$router.push({
path: "/home",
query: { id: 1 },
});
// 在home页面接收参数 this.$route.query.id
2. 参数不会在地址栏显示
this.$router.push({
name: "/home",
params: { id: 1 },
});
// 在home页面接收参数 this.$route.params.id
注意: 一个是name,一个是path
2. router-link标签跳转传参
{
path:'/home',
name:"home",
component:home
},
<router-link :to="{name:'home',params:{id:1}}">点击跳转</router-link>
// 在home页面接收参数 this.$route.params.id
3.window.href 传参
window.location.href = '/home/?id='+1;