-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
fix(v-model): keep the same behavior as v-model
with undefined
value with 2.x
#1530
Conversation
v-model
with undefined
insistent as 2.xv-model
with undefined
value with 2.x
@@ -85,6 +85,7 @@ export const vModelText: ModelDirective< | |||
return | |||
} | |||
} | |||
if (value === undefined || value === null) value = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Literally assigning NULL to native input value should has same effect. Probably checks value === null
and value !== null
is not required.
Check out example:
- Open: https://codesandbox.io/s/native-input-value-nwjoz?file=/index.js
- See console logs
@@ -47,7 +47,7 @@ export const vModelText: ModelDirective< | |||
HTMLInputElement | HTMLTextAreaElement | |||
> = { | |||
beforeMount(el, { value, modifiers: { lazy, trim, number } }, vnode) { | |||
el.value = value | |||
if (value !== undefined && value !== null) el.value = value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should also be able to do
if (value !== undefined && value !== null) el.value = value | |
if (value != null) el.value = value |
@@ -85,6 +85,7 @@ export const vModelText: ModelDirective< | |||
return | |||
} | |||
} | |||
if (value === undefined || value === null) value = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above:
if (value === undefined || value === null) value = '' | |
if (value == null) value = '' |
fix #1528