Posts

Showing posts with the label vue-component

Vue Router Child component being called first than parent

Image
Clash Royale CLAN TAG #URR8PPP Vue Router Child component being called first than parent I'm using the Vue Cli with vue-router. I created this structure in my route: { path: '/admin', component: Layout, children: [ { path: '/', component: Home, meta: { requiresAuth: true } }, There is a hierarchically larger component: layout. And the routes call the child components. Example: Home. I make an ajax call in the Layout component, and the Home component needs to manipulate the request response data. The problem is that the Home component is being called first than the component Layout. If the Home component is a sub router of the layout component, why is the component Home being called first? Does anyone know how to respond? By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continue...

Cannot access this.$route in Vue class constructor with Vue-Router >= 2.6.0

Image
Clash Royale CLAN TAG #URR8PPP Cannot access this.$route in Vue class constructor with Vue-Router >= 2.6.0 I upgraded our Vue project to the latest versions of its packages, including Vue-Router from 2.5.3 to 2.7.0. Suddenly several of our modules have stopped working because we can no longer access this.$route in the constructor. @Component({ template, name: 'Something' }) export class Something extends Vue { someParam: string; constructor() { super(); // Works in Vue-Router 2.5.3, not in >= 2.6.0, get a null ref exception this.someParam = this.$route.params.someParam; } } I started moving what I can to Vue's beforeCreate() lifecycle hook, but these assignments are all over the project. What changed in vue-router that broke this? (or was this never supposed to work in the first place?) Is there an easier way to fix this than scouring through the project moving all these assignments from the constructor to beforeCreate()? For that matter, what wo...