After implementing the vue-property-decorator package, I encountered an issue when trying to use a mixin method inside the beforeRouteEnter hook.
Here is what I initially tried:
import { Component, Mixins } from 'vue-property-decorator';
import { myMixin } from '../mixins';
@Component({})
export default class myClass extends Mixins(myMixin) {
beforeRouteEnter(to, from, next) {
next(vm => {
vm.callMixinMethod();
})
}
}
The problem with this approach is that the types of to
, from
, next
, and vm
are not automatically assigned.
To address this issue, I moved the beforeRouteEnter hook into @Component:
@Component({
beforeRouteEnter(to, from, next) {
next(vm => {
vm.callMixinMethod();
})
}
})
This solution successfully assigns types automatically. However, a new problem arises as the mixin method is no longer defined within @Component. This results in the error message:
Property 'callMixinMethod' does not exist on type 'Vue'
I attempted to register mixins inside @Component like so:
@Component({
mixins: [myMixin],
beforeRouteEnter...
})
Unfortunately, this did not resolve the issue.
Is there a way to enable the beforeRouteEnter hook inside @Component to access the methods of imported mixins? Perhaps by extending vm
with mixins somehow?