使用代码的方式传递:
//路由定义要命名name
{
path: '/commun',
name: 'KnowledgeCommun',
component: KnowledgeCommun,
children: [
{
path: '',
name: 'RandomLook',
component: RandomLook
}, {
path: 'publish',
name: 'MyPublish',
component: MyPublish
}, {
path: 'reply',
name: 'ReplyMe',
component: ReplyMe
}, {
path: 'collect',
name: 'MyCollect',
component: MyCollect
}
]
}
//在父组件中传递userId这个属性,使用名称识别路径
this.$router.push({name: ‘RandomLook’, params: {userId: '123'}});
//子组件中获取参数
//创建页面时获取参数
//是this.$route 不是this.$router
created() {
this.getRouterData();
},
methods: {
getRouterData() {
this.userId = this.$route.params.userId;
}
}
网友评论