query传参
this.$router.push({
path,
query: {
userprofile: this.userprofile,
},
});
路由里这样配置
{
path: '/userpage',
component: UserPage,
props(route) {
return {
userprofile: route.query.userprofile
}
}
}
params传参
必须使用name命名路由组件
{
name: 'recommend',
path: '/songsheet:id',
component: SongSheet,
props(route) {
return {
id: route.params.id
}
}
},
this.$router.push({
name:'recommend'
params: {
userprofile: this.userprofile,
},
});
接收参数:在组件里props:['xxx']