Vue: Binding v-model to array items

Created on 31 Oct 2014  路  4Comments  路  Source: vuejs/vue

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).

Most helpful comment

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

All 4 comments

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

I hope this was mentioned in the documentations

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

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fergaldoyle picture fergaldoyle  路  3Comments

gkiely picture gkiely  路  3Comments

finico picture finico  路  3Comments

robertleeplummerjr picture robertleeplummerjr  路  3Comments

bdedardel picture bdedardel  路  3Comments