0👍
Add the values to your configuration object and add a value attribute to each field. Alternatively you can have a separate configuration object array and a values array, and match them with the index of your field.
export default {
name: "child1",
data() {
return {
formItems: [
{
label: "test1",
value: "",
},
{
label: "test2",
value: "",
},
],
};
},
computed: {
allValues() {
return this.formItems.map(({ value }) => value);
},
},
methods: {
addField(label, value = "") {
this.formItems.push({
label,
value,
});
},
},
};
In this example we start off with two fields. The button adds new fields by modifying formItems
. allValues
is an example of a computed property that gets all the values. You probably want to loop over formItems
though in an actual application so you know what field the value belongs to. If you get your fields from an api, modify the response in such a way that you have all the information that belongs to a field in one ‘field’ object, so you can easily access it and process it later once values have changed.
Source:stackexchange.com