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