作用:点击路由跳转携带参数
方法一:通过动态路由传递参数,当前活跃路由页面获取参数通过(this.$route.params.动态参数)获取
{
path: "/user/:userId",
component: User
}
<router-link :to="'/user/' + userId">link标签</router-link>
<button @click="btnClick">btn</button>
btnClick() {
this.$router.push('/user/' + this.userId);
}
this.$route.params.userId
方法二:通过query传递参数,当前活跃路由页面获取参数通过(this.$route.query.参数)获取
<router-link :to="{path: '/profile', query: {name: '孙悟空', age: 19, height: 1.88}}">
通过router-link标签query传递
</router-link>
this.$route.query.name;
this.$route.query.age;
<button @click="btnClick()">通过普通标签query传递</button>
btnClick() {
this.$router.push({
path: "/profile",
query: {
name: "孙悟空",
age: 19,
height: 1.88
}
})
}
this.$route.query.name;
this.$route.query.age;