[Vuejs]-Vue form repeater with parent and child

0👍

Try this out.

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

        addChildren: function (indexp) {
          console.log(indexp);
          
            this.form.parent[indexp].children.push({
                child: {
                    name: '',
                    school: '',
                }
            });
          console.log(this.form.parent)
        },
    }

I made some changes to your code:

  • Added a property children of type array to parent object
  • Changed addChildren function. Now child element is pushed into the children array of the parent of index passed to addChildren function

Leave a comment