vue路由传参的三种基本方式

方式一:

  路由配置:

   {
     path: '/describe/:id',
     name: 'Describe',
     component: Describe
   }
 传递方法:
 getDescribe(id) {
//   直接调用$router.push 实现携带参数的跳转
        this.$router.push({
          path: `/describe/${id}`,
        })
获取方法:
  this.$route.params.id

方法二:
  路由配置:
  {
     path: '/describe',
     name: 'Describe',
     component: Describe
   }
  传递方法:
   this.$router.push({
          name: 'Describe',
          params: {
            id: id
          }
        })
  获取方法:
    this.$route.params.id
 
方法三:
  路由配置:
  {
     path: '/describe',
     name: 'Describe',
     component: Describe
   }
  传递方法:
    this.$router.push({
          path: '/describe',
          query: {
            id: id
          }
        })

  获取方法:
    this.$route.query.id
 
 
posted @ 2019-03-21 18:35  qijiamin  阅读(429)  评论(0编辑  收藏  举报