-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
v-model with uninitialized property #3732
Comments
This is an intended change in 2.0 - |
@yyx990803 is there any other way i can do this in vue2? |
It's ok that non-existent properties of |
When building large forms, I now need to duplicate all property names in the template, the data initialiser function (for create) and make sure any objects that are edited have all possible properties present (null value for missing properties) before binding them in vue. v-model still creates the properties without warning, but not as a reactive property, meaning some properties become reactive and some not, leading to strange behaviour. (for instance when using computed properties) A custom v-model directive can be a solution, but it's a pity the default behaviour has changed. |
@yyx990803 we definitely need this as well to have bindings to non-existend sub-properties. Any workarounds? The models we're dealing with here are way to big to provide default stuff (also, this is send to the API and is just messy). |
@codeofsumit You should always try to fill the |
@posva I'll follow up on this in the forums. Thank you! |
According Vue's documentation, The problem is that WHILE IT STILL CREATES THE PROPERTY it does not make it reactive, so when you combine it with a v-for with dynamically added objects you could end up with a collection of objects, some of them reactive and some of them not reactive. But, as I said, v-model still creates the property, so the desired effect of motivating you to declare things properly is achieved by the silent threat of reactiveness bugs exploding on your user's faces instead of a proper warning or just the mitigation of a more common sense v-model behavior. So to get what we all (except Evan) want, we should stop using |
This behavior has been reverted, after a long discussion in #5932 |
Vue.js version
2.0 rc
Reproduction Link
http://codepen.io/anon/pen/xEqbmN?editors=1010#0
What is Expected?
Not sure if this is what is expected in Vue 2.0. Tried to search but couldn't find anything.
e.g:
If you pass an uninitialized property (
model.b
) tov-model
, it's obviously not reactive so bindings won't update or a deep watch onthis.model
won't fire off either.Any chance that
v-model
could useVue.set
internally if it detects a binding with valueundefined
to automatically create reactive properties? (like Vue 1.0)Or failing that, it should
warn
when an uninitialized property is passed tov-model
The text was updated successfully, but these errors were encountered: