vue项目中在需要不同页面之间跳转并且传递数据时,通常会使用router.push较为方便,当然使用windows.href和sessionStorage一起用也可以达到效果,但是sessionStorage通常储存的是全局性常用的变量。而router.push传递的参数生命周期很短,当跳转的页面关闭或跳转至其他页面时,参数生命周期结束。一起来看router.push的使用方法:
1.不传参数的跳转:

this.$router.push('./lastPage')//跳转至当前目录的lastPage页面

或者用路由名字:

this.$router.push('ResourceTable')//跳转至路由名为ResourceTable的页面

VUE使用router.push实现页面跳转和传参
2.带参数:
用pararms传递:(注意前面一定是name

this.$router.push({ name: 'ResourceTable', params: { myId: 123 }})//跳转至ResourceTable路由并传递一个数据

接受参数

this.$route.params.myId //将返回123

用query传递:(注意前面一定是path

this.$router.push({ path: './ResourceTable', query: { myId: 123 }})//跳转当前目录ResourceTable路由并传递一个数据

接受参数

this.$route.query.myId //将返回123

相关文章:

  • 2021-11-28
  • 2021-11-28
  • 2021-11-28
  • 2022-12-23
  • 2021-11-28
  • 2021-07-16
  • 2021-11-22
猜你喜欢
  • 2021-12-20
  • 2022-12-23
  • 2022-03-01
  • 2022-12-23
  • 2021-11-28
  • 2021-11-28
  • 2021-11-28
相关资源
相似解决方案