I'm currently working on a Vue 2 project with TS using these libraries for component setup : vue-class-component and vue-property-decorator
I need to create a form component, but I'm having a hard time with data binding, because when I use the data() option for my form component it produces errors on compile time.
Is there a way to bind input data without using the data() option ?
The errors I get :
ERROR in /path/to/components/folder/Form.vue
Property 'id' does not exist in type 'Form'.
For more context here's my code :
@Component
export default class Form extends Vue {
//Bind form data
data() {
return {
id: "",
name: "",
age: 0,
amountA: 0,
amountB: 0,
capitalA: 0,
capitalB: 0
}
}
onSubmit(e: any): void {
e.preventDefault();
//Create new class object
const newClass = {
id: this.id,
name: this.name,
age: this.age,
amountA: this.amountA,
amountB: this.amountB,
capitalA: this.capitalA,
capitalB: this.capitalB
}
//Emit the class object to parent component
this.$emit("add-class", newClass);
this.$emit("update-total");
//Reset Form
this.id = ""
this.name = ""
this.age = 0
this.amountA = 0
this.amountB = 0
this.capitalA = 0
this.capitalB = 0
}
And here's the error on my console: Console error
Can anyone helps me to get ride of these error. Thank you!