WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are cases that you want to use your component type on a function in `@Component` decorator argument.
4
+
For example, to access component methods in a watch handler:
5
+
6
+
```ts
7
+
@Component({
8
+
watch: {
9
+
postId(id:string) {
10
+
// To fetch post data when the id is changed.
11
+
this.fetchPost(id) // -> Property 'fetchPost' does not exist on type 'Vue'.
12
+
}
13
+
}
14
+
})
15
+
classPostextendsVue {
16
+
postId:string
17
+
18
+
fetchPost(postId:string):Promise<void> {
19
+
// ...
20
+
}
21
+
}
22
+
```
23
+
24
+
The above code produces a type error that indicates `fetchPost` does not exist on `this` in the watch handler. This happens because `this` type in `@Component` decorator argument is the base `Vue` type.
25
+
26
+
To use your own component type (in this case `Post`), you can annotate the decorator through its type parameter.
27
+
28
+
```ts
29
+
// Annotate the decorator with the component type 'Post' so that `this` type in
0 commit comments