Skip to content

Setter not called when binding multiple checkboxes to the same array #249

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

Closed
chrome-cgi opened this issue Jul 12, 2016 · 2 comments
Closed

Comments

@chrome-cgi
Copy link

Hi,

I like the form handling style using computed property setter, for its less verbosity.
But when I use it with multiple checkboxes bound to the same array, the property setter is never called and I got an error: "[vuex] Do not mutate vuex store state outside mutation handlers" if strict option is set to be true.

Here is an example:
https://jsfiddle.net/chrome_cgi/37q0h6xa/4/

This may be because Vue pushes the value directly into the model in its checkbox listener function.

I somehow got to work by patching Vue to call the setter with newly created array, but I'm not sure if this is an appropriate way.

Is this a bug or an intended behavior, and should I avoid using setter with an array typed v-model?

Thanks.

@yyx990803
Copy link
Member

This is because v-model when bound to a checkbox array, directly mutates the array with push instead of replacing the array. You probably want to use a watcher instead.

@chrome-cgi
Copy link
Author

I got it, thanks a lot!

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

2 participants