undefinedfix
Sign in

Vue + typescript cannot use beforerouteenter ()

draft04 edited in Sun, 22 May 2022

main.ts Import component from 'Vue class component' is configured as follows; Component.registerHooks ([

'beforeRouteEnter',
'beforeRouteLeave',
'beforeRouteUpdate',

]);

However, private beforerouteupdate (to: route, form: route, next: () = > void): void is not executed when beforerouteenter() is used in the component{

console.log(11)
next();

}

4 Replies
Ove
commented on Mon, 23 May 2022

Execute in the new JS file

//registerHooks.js
import Component from 'vue-class-component'

Component.registerHooks([
 'beforeRouteEnter',
 'beforeRouteLeave',
 'beforeRouteUpdate'     
])

And then in the main.ts Top introduction registerHooks.js

ryotl
commented on Mon, 23 May 2022

    import { Component } from 'vue-property-decorator';
    
    Component.registerHooks([
      'beforeRouteEnter',
    ])
PatrickJD
commented on Mon, 23 May 2022

If you just want to update the view, you can consider listening to the route

    @Watch('$route')
    routeWatch() {
        this.loadData();
    }

I use vue-cli3, @ watch is

import { Component, Prop, Vue, Watch } from 'vue-property-decorator';
Bearmatt
commented on Mon, 23 May 2022

How was it solved later? I also had this problem

lock This question has been locked and the reply function has been disabled.