Field value is getting pushed to wrong array
Solution 1:
Try like following snippet:
const { ref } = Vue
const app = Vue.createApp({
setup () {
const fieldsArray = ref([])
const fieldHeader = ref([])
const handleAddField = () => {
fieldHeader.value.push({name: '', desc: ''});
fieldsArray.value.push({imgOne: null});
};
const onSelected = () => { }
return { fieldsArray, fieldHeader, handleAddField, onSelected }
}
})
app.use(Quasar)
app.mount('#q-app')
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons" rel="stylesheet" type="text/css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/quasar.prod.css" rel="stylesheet" type="text/css">
<div id="q-app">
<div v-for="(field, i) in fieldsArray" :key="i" >
<q-input
label="Name"
v-model="fieldHeader[i].name"
type="text"
dense
></q-input>
<q-input
v-model="fieldHeader[i].desc"
type="textarea"
></q-input>
<q-file
v-model="fieldsArray[i].imgOne"
@update:model-value="onSelected()"
></q-file>
</div>
<q-btn @click="handleAddField">Add Field</q-btn>
<p>fieldsArray: {{fieldsArray}}</p>
<p>fieldHeader: {{fieldHeader}}</p>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/quasar.umd.prod.js"></script>