Answer the question
In order to leave comments, you need to log in
How to pass parameters to a component via routing in vuejs?
I have a vue root component that renders the page. There are several more child components on the page that are displayed depending on the selected tabs. This switching between components via vue-route is organized. Task: from the root component to pass parameters to the child ones.
The component itself:
export default Vue.component('main-page', {
props : ['settings'],
mounted(){
console.log(this.settings); // Все нормально
},
created(){
console.log(this.settings); // Все нормально
},
router: new VueRouter({
routes: [
{ path: '/calendar', component: calendar, props: {
settings: <b>this.settings</b> // Все плохо
}},
{ path: '/groups', component: Groups },
{ path: '/mail', component: Mail },
{ path: '/tests', component: Tests },
{ path: '*', redirect: '/calendar' }
]
}),
render: h => h(Page)
})
const Groups = { template: '<div>Groups</div>' };
const Mail = { template: '<div>Mail</div>' };
const Tests = { template: '<div>Tests</div>' };
const routes = [
{ path: '/calendar', component: calendar, props:{}},
{ path: '/groups', component: Groups },
{ path: '/mail', component: Mail },
{ path: '/tests', component: Tests },
{ path: '*', redirect: '/calendar' }
];
const router = new VueRouter({routes});
export default Vue.component('main-page', {
props : ['settings'],
created(){
routes[0].props.settings = this.settings
},
router,
render: h => h(Page)
})
Answer the question
In order to leave comments, you need to log in
<router-view :prop="var">
works, but in general, if such a question arises, then I would look towards vuex
I didn’t understand the question exactly, but you can contact the parent like thisthis.$parent.что-то
I'm no expert, but have you tried props: true ? https://router.vuejs.org/en/essentials/passing-pro...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question