一、通过 props 解耦

  1. {
  2. path:'detail/:id',
  3. component:import('../views/Detail.vue'),
  4. props:true
  5. }

二、Detail页面通过props属性接收

  1. export default {
  2. name: "Detail",
  3. props:['id']
  4. }

三、动态路由跳转

3-1 router-link跳转

  1. //配置
  2. {
  3. path: '/detail/:id',
  4. name: 'detail',
  5. component: () => import('../views/Detail.vue')
  6. }
  7. //传变量
  8. <router-link :to="'/detail/'+item.id" tag="button">
  9. 跳转到detail
  10. </router-link>
  11. //接收
  12. this.$route.params

3-2 结合命名路由的使用

  1. <router-link :to="{name:'detail',params:{id:2324}}">detail</router-link>

3-3 $router.push()模式

  1. methods:{
  2. handleClick(){
  3. this.$router.push({name:'detail',params:{id:2133}})
  4. }
  5. }
  1. methods:{
  2. handleClick(){
  3. this.$router.push({path:'/detail/1213'})
  4. }
  5. }
  1. methods:{
  2. handleClick(){
  3. this.$router.push('/detail/1213')
  4. }
  5. }