vue中this.$router.push()路由传值和获取的两种常见方法

路由配置
vue中this.$router.push()路由传值和获取的两种常见方法

1.params
由于动态路由也是传递params的,所以在 this.$router.push() 方法中path不能和params一起使用,否则params将无效。需要用name来指定页面。

通过name和params传递参数
this.$router.push({ name: ‘index’, params: { username: “fatjack”, password: 123 }})

获取
this.$route.params.username
vue中this.$router.push()路由传值和获取的两种常见方法

2.query

通过path和query传递参数
this.$router.push({path: ‘/index’, query: { username: “fatjack”, password: 123 }});

获取
this.$route.query.username