vue-router params和query的区别

作者: 玄月府的小妖在debug | 来源:发表于2017-11-17 17:18 被阅读214次

eg.

1.query

  this.$router.push({
        path: 'newApply',
        query: {
          type: item.key,
          typeDesc: item.value
        }
      })

2.params

  this.$router.push({
        name: 'newApply',
        params: {
          type: item.key,
          typeDesc: item.value
        }
      })

比较用法

1.用法
query要用path来引入,params要用name来引入,接收参数都是类似的,分别是this.$route.query.name和this.$route.params.name。
2.url地址显示
query更加类似于我们ajax中get传参,params则类似于post,说的再简单一点,前者在浏览器地址栏中显示参数,后者则不显示
query

http://localhost:8080/workorder/newApply?type=BOX_DEPLOY&typeDesc=%E5%B0%8F%E7%99%BD%E7%9B%92%E9%83%A8%E7%BD%B2

params

http://localhost:8080/workorder/newApply

3.注意点
query刷新不会丢失query里面的数据
params刷新 会会 丢失 params里面的数据

相关文章

网友评论

  • 梦里星:params刷新没有了数据,怎么办呢,那params还有何作用

本文标题:vue-router params和query的区别

本文链接:https://www.haomeiwen.com/subject/knrjvxtx.html