[Vuejs]-Vue how to add form repeater in another

0👍

Apparently, you are pushing into an object not an array. Your default state value is

    form: {
       first: [{
           second: []
       }],
    },

You see the element in ‘first’ is not an array its an object. When addFirstRepeater is being called it’s adding an object in the array. So in addSecondRepeater, this.form.first[index] points to an object not an array, and push() function is available with arrays not objects.

If you intent to use only 1 element in your main array (which I assume you do as I can see it in code) you may add this to addSecondRepeater

 this.form.first[0][index].push()

instead of

this.form.first[index].push()

Where ‘index’ is the key of the key value pair in the object at 0th index of array ‘first’

Leave a comment