19、vue 路由传参中刷新页面参数丢失 及传参的几种方式?

目前测试俩种方法均可
传参方式1:

 1)父组件通过name来匹配
                this.$router.push({
                      name: 'Describe',
                      params: {
                                   id: id
                      }
             })

         2)相应路由配置:
                 {
                      path: '/describe/:id',
                      name: 'Describe',
                      component: Describe
                  }
         3)子组件是通过:
                 this.$route.params.id

传参方式2:

  父组件:this.$router.push({
                        path: '/describe',
                        query: {
                                      id: id
                        }
                    })

    路由设置:
                    {
                         path: '/describe',
                         name: 'Describe',
                         component: Describe
                     }

     子组件获取:
                   
             this. $route.query.id
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容