vue this.$router.push()传参

第一种  params 传参

patams传参,路径不能使用path

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

获取数据:this.$route.params.type

第二种 query

this.$router.push({path: '/user/index', query: {type: 1}})

获取数据: 取数据:this.$route.query.type

注意:

  params传参,push里面只能是 name:'xxxx',不能是path:'/xxx',因为params只能用name来引入路由,如果这里写成了path,接收参数页面会是undefined!!!

另外,二者还有点区别,直白的来说query相当于get请求,页面跳转的时候,可以在地址栏看到请求参数,而params相当于post请求,参数不会再地址栏中显示

注意:传参是this.$router,接收参数是this.$route,这里千万要看清了!!!

posted @ 2018-12-19 12:29  拥之则安丶伴之则暖  阅读(1802)  评论(0编辑  收藏  举报