-
Notifications
You must be signed in to change notification settings - Fork 434
feat: add lifecycle types into vue instance type #371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@ktsn In the README, |
If you want to make it work with custom hooks, you can manually add it by yourself: | ||
|
||
```ts | ||
import Vue from 'vue' | ||
import { Route, RawLocation } from 'vue-router' | ||
|
||
declare module 'vue/types/vue' { | ||
// Augment component instance type | ||
interface Vue { | ||
beforeRouteEnter?( | ||
to: Route, | ||
from: Route, | ||
next: (to?: RawLocation | false | ((vm: V) => any) | void) => void | ||
): void | ||
|
||
beforeRouteLeave?( | ||
to: Route, | ||
from: Route, | ||
next: (to?: RawLocation | false | ((vm: V) => any) | void) => void | ||
): void | ||
|
||
beforeRouteUpdate?( | ||
to: Route, | ||
from: Route, | ||
next: (to?: RawLocation | false | ((vm: V) => any) | void) => void | ||
): void | ||
} | ||
} | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ktsn In which file should this code be added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a new .ts
file in your project and write in it. You may want to see Vue.js TypeScript guide. https://vuejs.org/v2/guide/typescript.html#Augmenting-Types-for-Use-with-Plugins
fix #338
fix #297