vue $router.push 传参的问题

$router 和 $route的区别

  $route为当前router跳转对象里面可以获取name、path、query、params等

  $router为VueRouter实例,想要导航到不同URL,则使用$router.push方法

  返回上一个history也是使用$router.go方法

$router.push()

  1.params 传参

    注意⚠️:patams传参 ,路径不能使用path 只能使用name,不然获取不到传的数据

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

    取数据:this.$route.params.id

  2.query传参

  

this.$router.push({path: 'good', query: {id: 2}})

  取数据:this.$route.query.id

  

posted @ 2018-10-28 17:21  Duan?  阅读(5442)  评论(0编辑  收藏  举报