vue 学习笔记(二)

1、路由传参

  路由传参分为两种模式:params和query

params模式:

this.$router.push({name: 'user', params: {userID: '123'}})

  注意点:

  A .  需要在router路由中指明name,如下。如果不想参数在地址栏中显示,可以将  :id  隐藏

{ path: '/user/:id',name:'user', component: User }

  B.  采用params模式,不能使用path指明路径

  C. 获取参数: this.$route.params.userID

query模式:

this.$router.push({path: '/user', query: {userID: '123'}})

  注意点:采用query模块传参,参数会在地址栏中显示。

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

 

2、$router 和 $route 的区别

  $router: 传参 

  $route:获取当前路由跳转对象中的信息

  

posted on 2018-11-19 10:14  bala001  阅读(169)  评论(0编辑  收藏  举报

导航