I have this code in my vue app, it will create dynamic input fields
<div class="col-sm-12 col-md-12 col-lg-12 mt-1 mb-1">
<a class="text-uppercase text-decoration-none text-dark" href="#" @click.prevent="addField">
<i class="bi bi-plus"></i>
Add device properties
</a>
</div>
<div class="col-sm-12 col-md-4 col-lg-4 mt-1 mb-1" v-for="inputs in fieldsCounter" :key="inputs">
<div class="input-group">
<input type="text" class="form-control text-uppercase rounded-0 me-1" v-model="deviceDetails.fieldName" placeholder="Field Name" @change="log">
<input type="text" class="form-control text-uppercase rounded-0 ms-1" v-model="deviceDetails.fieldValue" placeholder="Field Value" @change="log">
</div>
</div>
My method to create the fields is this:
addField(){
this.deviceDetails.push({})
}
I need to create dynamic input fields but my problem is that I’m not able to get the v-model data of the new created fields. How I can solve this problem and create inputs corectly with a v-model assigned for each new input field??H
2
Answers
Use
v-for
withv-model
If I uderstood You correctly try like following snippet: