vue中this.$router.push路由传参方法

在vue项目中通过this.$router.push路由跳转页面传递参数的方式经常用到,一般有两种方式:

1.name+params传参方式:[name为要跳转的路由名,params为要传递的参数]

this.$router.push({name:'success',params:{username:'tom',value:'04652'}});

 注意:如果要传递多个参数,可以先封装成对象传递

接收:this.$route.params.username 

2.path+query传参方式:[path为要跳转的路由路径,query为要传递的参数]

this.$router.push({path:'/login/success',query:{username:'tom',value:'04652'}});

接收:this.$route.query.username 

ps:这两种传参方式最主要的区别就是query传参参数拼接到浏览器url地址中,而params不会。

根据实际应用场景来使用这两种方式

猜你喜欢

转载自blog.csdn.net/JxiaoZhang/article/details/85335915