vue 2.0.3 v-model not updating using an array

Created on 16 Oct 2016  ·  6Comments  ·  Source: vuejs/vue

I'm in process migrating an application from Vue 1.x to 2.0.3. In this application I'm having several selects where each v-model binds to an individual index of an array . This is without problems in Vue 1.x but in version 2 it does not update. I believe this is a potential bug.

I have reproduced the problem here:
https://jsfiddle.net/peterkorgaard/a7vvz753/18/

Vue.js version

2.0.3

Reproduction Link

https://jsfiddle.net/peterkorgaard/a7vvz753/18/

Steps to reproduce

What is Expected?

What is actually happening?

bug

Most helpful comment

You should use object type, as model binding uses model[index]= in internal implementation. If you use array type, the value could not be observed. http://vuejs.org/guide/list.html#Caveats

You could init the selections when created, and update the selections after the selectBoxes data updated.

I update the fiddler here https://jsfiddle.net/defcc/a7vvz753/21/

All 6 comments

I am looking into this. Seems selections do not get Observered correctly

@peterkorgaard I update the fiddler here https://jsfiddle.net/defcc/a7vvz753/20/, You could use like this as a workaround.

For more info, take a look at this http://vuejs.org/guide/reactivity.html#Change-Detection-Caveats

I got the same question.

@defcc Your solution can solve that we already know how many items of the model. If change the model from array to object, how can we do?

You should use object type, as model binding uses model[index]= in internal implementation. If you use array type, the value could not be observed. http://vuejs.org/guide/list.html#Caveats

You could init the selections when created, and update the selections after the selectBoxes data updated.

I update the fiddler here https://jsfiddle.net/defcc/a7vvz753/21/

@defcc Bravo, this solution worked for me fine. Thank you so much!

Thank you, @defcc, for clarifying this. I will use this workaround until the problem gets solved. And thanks for the great work everybody does on Vue. I'm really amazed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

loki0609 picture loki0609  ·  3Comments

paceband picture paceband  ·  3Comments

lmnsg picture lmnsg  ·  3Comments

hiendv picture hiendv  ·  3Comments

aviggngyv picture aviggngyv  ·  3Comments