I want to create a dynamic form fields to add multiple names using vue js sample output -> https://prnt.sc/h6y0pf
here's my html
<div id="app">
<h1>Vue JS Multiple Fields Repeater</h1>
<div class="border" v-for="field in field1">
<input v-model="field.value" placeholder="Enter First Name">
<input v-model="field2.value" placeholder="Enter Last Name">
</div>
<button @click="AddField">
New Field
</button>
<pre>{{ $data | json }}</pre>
</div>
here's my vuejs
new Vue({
el: '#app',
data: {
field1: [] ,
field2: []
},
created: function() {
this.field1.push({ value: '' });
this.field2.push({ value: '' });
},
methods: {
AddField: function () {
this.field1.push({ value: '' });
this.field2.push({ value: '' });
}
}
});
I've created a jsfiddle here -> https://jsfiddle.net/0e3csn5y/2/
The problem is that only the first name can be populated everytime i add a new field. How can i also do that to last name field? How can we do the tricky part here?
1inv-model="field.value"You don't havefielddata butfield1fielddata comes fromfield1array