I am a beginner with vue.js and currently working on a form. I have an add button in my form, so when the user clicks on it, the same form field will be added to the form. Users can add as many times as they want. Here is my initial data:
data () {
return {
form: [{
fieldOne: '',
fieldTwo: '',
}]
}
}
When the user clicks on the add button in HTML, my addForm function is triggered.
addForm() {
let newObject = {
fieldOne: '',
fieldTwo: '',
}
this.form.push(newObject); // However, this gives me an error.
}
I have come across Vue.set, which allows adding single fields or objects easily. But I'm unsure about how to add an object to my form array.
Any assistance would be greatly appreciated.