[Vuejs]-JavaScript add object to existing object

0👍

In your codepen the problem is that you are using the same array for parents and children, so both addParent and addChildren function edit the same array.

addParent: function () {
            this.form.parent.push({
                name: '',
                age: '',
            });
        },

addChildren: function (index) {
          console.log(index);
          this.form.parent.splice([index], 0, {
               child: {
                  name: '',
                  school: '',
               }
          });
        },

I think that what you want is that for each item in parents array there is an array of children. Try out this pen and let me know if I correctly understand your problem

Leave a comment