0

I have a plain array of strings in my data and I would like to enable their editing/adding with

<ul>
    <li v-for="(string, index) in strings" :key="index">
       <input v-model="string">
    </li>
</ul>

the problem is that the strings in the array are not changed when the user types in the input.

Here is a Jsfiddle https://jsfiddle.net/franta/74ybd0g5/10/ I would like the "Strings" part to work like the "Things".

Thanks

3
  • 2
    pass the reference instead of a value? strings[i] Commented Jun 9, 2020 at 12:55
  • 1
    Does this answer your question? Why v-model doesn't work with an array and v-for loop? Commented Jun 9, 2020 at 13:07
  • @cesartalves thanks that explains why it does not work but it does not say how to work with arrays of plan strings (using strings[index]) Commented Jun 10, 2020 at 7:17

1 Answer 1

1

Try this: v-model="strings[index]"

By doing this you are passing by reference and not by value. Meaning, instead of having two separate instances between strings and your v-model="string" they both share the same instance instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.