I'm migrating my Vue 2 project from JS to TS with class-based components. In my code, I used vue-router
by accessing this.$route
and this.$router
properties. However, in class-based Typescript components, accessing these properties obviously gives a compile-time error, because they are defined dynamically at runtime by VueRouter
plugin.
// Something like this works fine in my JS-based Vue components
export default {
methods: {
route() {
return this.$route;
}
}
}
// Compile time error: TS2339: Property '$route' does not exist on type 'RouteUser'.
@Component
export default class RouteUser extends Vue {
route() {
return this.$route;
}
}
Then how do I use vue-router
and vue-class-component
together?