vue的路由跳转及传参(编程式导航)


1)直接在路由中传参

   this.$router.push({ path: `/childPage/${id}`, })

    需要对应路由配置如下:

 
 { path: '/childPage/:id', name: 'childPage', component: childPage }

获取参数:this.$route.parames.id

2) 通过路由属性中的name来确定匹配的路由,通过params来传递参数

   this.$router.push({ name: 'childPage', params: { id: id } })

    需要对应路由配置如下:

    {

      path: '/childPage',

      name: 'childPage',

      component: childPage

     }

3) 使用path来匹配路由,然后通过query来传递参数

    this.$router.push({ path: '/childPage', query: { id: id } })

     需要对应路由配置如下:

       {

         path: '/childPage',

         name: 'childPage',

         component: childPage

       }

  获取参数:this.$route.query.id

 

 

 

参考:https://segmentfault.com/a/1190000012393587?utm_source=tag-newest☺


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM