1.使用query方式
/data?id=1 /data?id=2 这里的 id 叫 query
{ path:'detail/:id', name:product, component:Product } this.$router.push({path:'detail', query:{id:23}}) this.$router.push('detail?id=23')
2.使用params方式
/data/:id这个路由匹配/data/1,/data/2这里的 id 叫 params
params传参的时候,要在路由后面添加参数名,并且参数名称要和设置的参数名一样
{ path:'detail/:id', name:product, component:Product } <router-link :to={'detail', params:{id:23}}>//方法一 this.$router.push({name:'detail', params:{id:23}})//方法二 示效果:http://127.0.0.1:8080/#/detail/23
获取参数
this.$route.query.id this.$route.params.id