vue-router query和params参数的区别

1、query方式传参和接收参数(相当于get请求)

this.$router.push({
     path:'/home'
     query:{
          id:1
    }
})          

接收参数:
this.$route.query.id    

注意: 传参是this.$router, 接收参数是 this.$route

2、params 方式传参和接收参数, 相当于post请求

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

接收参数:
this.$route.params.id

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

猜你喜欢

转载自www.cnblogs.com/sllzhj/p/10883377.html