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

vue 2.0.3 v-model not updating using an array #3958

Closed
peterkorgaard opened this issue Oct 16, 2016 · 6 comments · Fixed by #3988
Closed

vue 2.0.3 v-model not updating using an array #3958

peterkorgaard opened this issue Oct 16, 2016 · 6 comments · Fixed by #3988
Assignees
Labels

Comments

@peterkorgaard
Copy link

peterkorgaard commented Oct 16, 2016

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?

@peterkorgaard peterkorgaard changed the title vue 2.0.3 v-model not update using an array vue 2.0.3 v-model not updating using an array Oct 16, 2016
@defcc
Copy link
Member

defcc commented Oct 17, 2016

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

@defcc defcc self-assigned this Oct 17, 2016
@defcc
Copy link
Member

defcc commented Oct 17, 2016

@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

@hpyer
Copy link

hpyer commented Oct 17, 2016

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?

@defcc
Copy link
Member

defcc commented Oct 17, 2016

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/

@hpyer
Copy link

hpyer commented Oct 17, 2016

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

@peterkorgaard
Copy link
Author

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.

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

Successfully merging a pull request may close this issue.

4 participants