使用代碼的方式傳遞:
//路由定義要命名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'}});
//子組件中獲取參數(shù)
//創(chuàng)建頁面時獲取參數(shù)
//是this.$route 不是this.$router
created() {
this.getRouterData();
},
methods: {
getRouterData() {
this.userId = this.$route.params.userId;
}
}