I am trying to create objects dynamically in an array and use v-model
with an input. Here is my code snippet:
This is the array structure
new_questions:{
questionrecord: []
}
This is the input field setup
<div class="form-fields" v-for="(field, index) in question_fields">
<div class="form-group">
<select class="form-control" v-model="new_questions.questionrecord[index].questionresponse">
<option value="single_answer">Single Answer (For regular question)</option>
<option value="multiple_answer">Multiple Answer (For situational judgement question)</option>
</select>
</div>
</div>
The expected output of the array should be like
new_questions:{
questionrecord: [
{
questiontype: "single_answer"
},
{
questiontype: "multiple_answer"
},
...
]
}
However, I encounter an error message:
[Vue warn]: Error in render: "TypeError: Cannot read property 'questionresponse' of undefined
Can anyone advise on how to fix this issue?