Working with Vue 3, I'm setting up a form that will display text input fields corresponding to a fixed-length array of strings. Each field's v-model should connect to the respective string in the array. Here is my current code snippet for the view:
<template
v-for="(myValue, index) in myValues"
:key="myValue"
>
<input
type="text"
class="form-control form-control-solid mb-3"
:placeholder="'Choice #' + (index + 1)"
v-model="myValues[index]"
/>
</template>
The property myValues
is defined as a ref<string[]>
in the setup method of my component. The form renders correctly, but I am encountering an issue where I can only enter one character at a time into each input field before losing focus. To continue typing, I have to click back into the field. If I remove the v-model
, I can freely input text without interruption.
I suspect this behavior is related to updating values in an array, but I'm unsure how to address it. Is there a way to allow multiple characters to be entered at once while still using v-model
?