Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding v-model to array items #530

Closed
dgerber opened this issue Oct 31, 2014 · 4 comments
Closed

Binding v-model to array items #530

dgerber opened this issue Oct 31, 2014 · 4 comments

Comments

@dgerber
Copy link

dgerber commented Oct 31, 2014

Following #333, any chance to support binding to array items out of the box?
http://jsfiddle.net/xb5h545w/
I guess the directive would have to convert items[0] into items.$set(0, x).

@yyx990803
Copy link
Member

There are some limitations with arrays of primitive values - but if you use arrays of objects it will work: http://jsfiddle.net/xb5h545w/1/

@perklet
Copy link

perklet commented Dec 3, 2018

I hope this was mentioned in the documentations

@Jugbot
Copy link

Jugbot commented May 21, 2019

To be clear, you have to use index operator instead of v-for?

@sirlancelot
Copy link

@Jugbot, you need to use v-bind:key or :key with the primitive value or the index of the array.

https://vuejs.org/v2/guide/list.html#Maintaining-State

<li v-for="item in items" :key="item"></li>
<!-- OR -->
<li v-for="(item, index) in items" :key="index"></li>

key's value must itself be a primitive value and it must be unique among its sibling elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants