My data is stored in an array. For each array item, there should be a text input in the form. When the user types into one of the text inputs, the array should be updated with the new values.
<div class="form-group" v-for="synonym in row.synonyms">
<input type="text" class="form-control" v-model="synonym" />
</div>
Here's a fiddle: https://jsfiddle.net/eywraw8t/122210/
The idea is when you type into one of the textboxes, the array value (shown below in that fiddle) should also update, but it doesn't.
This is the recommended way that Vue.js wants you to do it by using an index
(synonym, index)
:https://vuejs.org/v2/guide/list.html
If you wanted to do it another way you could introduce a method
v-on:blur
:Upon inspecting the console, you would find the following error:
Meaning, we need to give
v-model
access to a direct reference to the synonym and its index:The correct way to do it is to use an index, which vue.js provides in loops:
https://jsfiddle.net/m14vd89u/1/