Error when referencing props in component class or component methods from watchers
See original GitHub issueTo Reproduce
Create a new project with vue-cli and select Typescript and Class components as features
update HelloWorld.vue script section to
<script lang="ts">
import Vue from "vue"
import Component from "vue-class-component"
@Component({
props: {
msg: String
},
watch: {
msg: function () {
this.printMessage()
}
}
})
export default class HelloWorld extends Vue {
printMessage() {
console.log(this.msg)
}
}
</script>
Compile error
ERROR in /Users/tohe/Projects/test-class-component/src/components/HelloWorld.vue
40:12 Property 'printMessage' does not exist on type 'Vue'.
38 | watch: {
39 | msg: function () {
> 40 | this.printMessage()
| ^
41 | }
42 | }
43 | })
ERROR in /Users/tohe/Projects/test-class-component/src/components/HelloWorld.vue
46:22 Property 'msg' does not exist on type 'HelloWorld'.
44 | export default class HelloWorld extends Vue {
45 | printMessage() {
> 46 | console.log(this.msg)
| ^
47 | }
48 | }
49 | </script>
Versions
vue-cli 2.9.3 vue-class-component 6.1.2
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (3 by maintainers)
Top Results From Across the Web
VueJs single file component not reading data/props/methods
When I inspect this in chrome using vuejs devtools, I get the instance of the component, but it doesn't show that anything was...
Read more >Props | Vue.js
When objects and arrays are passed as props, while the child component cannot mutate the prop binding, it will be able to mutate...
Read more >Using Class Functions in Props for Components - Sentry
The Problem. Class functions are not bound to the class instance automatically, so if you attempt to use a class function that references...
Read more >How To Write Class-Based Components with Vue.js and ...
Use Angular-style class-based components in Vue with Typescript and vue-class-component.
Read more >Handling Errors in Vue.js - Raymond Camden
The third method I'll demonstrate is renderError. Unlike the previous two, this technique is component specific and not global. Also, like ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Please declare the props type as class properties and annotate your component type on
@Component
decorator or use vue-property-decorator.Oh, I just found a fix. Do this:
don’t miss the
!
afterid