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

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

或者用路由名字:

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

在这里插入图片描述
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 }
Logo

前往低代码交流专区

更多推荐