0👍
✅
Instead of trying to access the inputs in your handler, you could use a temporary variable in each array element to automatically store the corresponding input value, and then copy them over when you’re ready to save in modifyList()
:
-
Define
saveTemp()
to save the user’s input in a temporary variable (e.g.,__temp
) within the current array element (item
):saveTemp(item, key, value) { item.__temp = item.__temp || {}; item.__temp[key] = value; }
-
Add
<input>
change
-event handlers that callsaveTemp()
to store the input value in the current array element (t
):<td><input @change="saveTemp(t, 'name', $event.target.value)" :value="t.name"></td> <td><input @change="saveTemp(t, 'phone', $event.target.value)" :value="t.phone"></td> <td><input @change="saveTemp(t, 'email', $event.target.value)" :value="t.email"></td> <td><input @change="saveTemp(t, 'address', $event.target.value)" :value="t.address"></td>
-
Update the SAVE button’s
click
-handler to pass the array element (t
) instead ofindex
tomodifyList()
:<img v-b-tooltip.hover.bottom="'save'" v-on:click="modifyList(t)">
-
Update
modifyList()
to check for__temp
data to be committed, usingObject.assign()
:modifyList(item) { if (!item.disabled && item.__temp) { Object.assign(item, item.__temp); delete item.__temp; } },
Source:stackexchange.com