-
Notifications
You must be signed in to change notification settings - Fork 432
Error when referencing props in component class or component methods from watchers #220
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
Comments
Please declare the props type as class properties and annotate your component type on <script lang="ts">
import Vue from "vue"
import Component from "vue-class-component"
@Component<HelloWorld>({
props: {
msg: String
},
watch: {
msg: function () {
this.printMessage()
}
}
})
export default class HelloWorld extends Vue {
msg: string
printMessage() {
console.log(this.msg)
}
}
</script> |
The readme makes it look like you can use props from the decorator without having to declare them twice: Obviously this won't work because of microsoft/TypeScript#4881, but it is pretty misleading. |
The example in readme is written in JavaScript. If you want to see TS example, please see example directory in this repo. |
Ah, right. I forgot it was for babel too. Do you think this is a decent way to do it without the double declaration? const options = Vue.extend({
props: {
foo: String,
bar: Boolean
}
})
@Component
export default class FooBar extends options {
...
} |
Oh, it looks really nice idea 👍 |
It doesn't work
|
This does indeed not work, how did this make it into the docs? Am I missing something here. |
yep, does not work. you're either stuck with: @Component({
props: {
id: Number,
}
})
export default class SomeComponent extends Vue {
public id: number;
}
or @Component({
props: {
id: Number,
}
})
export default class SomeComponent extends Vue {
public id: number = -1; // initialize variable
}
|
Oh, I just found a fix. Do this: export default class LightSwitch extends Vue {
@Prop()
public id!: number;
} don't miss the |
not fix it. |
please explain why |
It's word very well, thank you so much |
Uh oh!
There was an error while loading. Please reload this page.
To Reproduce
Create a new project with vue-cli and select Typescript and Class components as features
update HelloWorld.vue script section to
Compile error
Versions
vue-cli 2.9.3
vue-class-component 6.1.2
The text was updated successfully, but these errors were encountered: