路由query和params区别

314 阅读1分钟

1、query

this.$router.push({
     path:'',
     name:'',
     query:{}
 })

接收:this.$route.query.xx query是拼接在url后面的参数,没有也没关系。

2、params

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

接收:this.$route.params.xx

params若在路由中设置后/name/:id/:sex,则必传,不传会导致跳转失败或者页面会没有内容。