fix(v-model): consistent nullish value handling with 2.x (#1530)
fix #1528
This commit is contained in:
parent
441c23602f
commit
425335c28b
@ -48,6 +48,7 @@ describe('vModel', () => {
|
|||||||
|
|
||||||
const input = root.querySelector('input')!
|
const input = root.querySelector('input')!
|
||||||
const data = root._vnode.component.data
|
const data = root._vnode.component.data
|
||||||
|
expect(input.value).toEqual('')
|
||||||
|
|
||||||
input.value = 'foo'
|
input.value = 'foo'
|
||||||
triggerEvent('input', input)
|
triggerEvent('input', input)
|
||||||
@ -57,6 +58,10 @@ describe('vModel', () => {
|
|||||||
data.value = 'bar'
|
data.value = 'bar'
|
||||||
await nextTick()
|
await nextTick()
|
||||||
expect(input.value).toEqual('bar')
|
expect(input.value).toEqual('bar')
|
||||||
|
|
||||||
|
data.value = undefined
|
||||||
|
await nextTick()
|
||||||
|
expect(input.value).toEqual('')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should work with multiple listeners', async () => {
|
it('should work with multiple listeners', async () => {
|
||||||
|
@ -47,7 +47,7 @@ export const vModelText: ModelDirective<
|
|||||||
HTMLInputElement | HTMLTextAreaElement
|
HTMLInputElement | HTMLTextAreaElement
|
||||||
> = {
|
> = {
|
||||||
beforeMount(el, { value, modifiers: { lazy, trim, number } }, vnode) {
|
beforeMount(el, { value, modifiers: { lazy, trim, number } }, vnode) {
|
||||||
el.value = value
|
el.value = value == null ? '' : value
|
||||||
el._assign = getModelAssigner(vnode)
|
el._assign = getModelAssigner(vnode)
|
||||||
const castToNumber = number || el.type === 'number'
|
const castToNumber = number || el.type === 'number'
|
||||||
addEventListener(el, lazy ? 'change' : 'input', e => {
|
addEventListener(el, lazy ? 'change' : 'input', e => {
|
||||||
@ -85,7 +85,7 @@ export const vModelText: ModelDirective<
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
el.value = value
|
el.value = value == null ? '' : value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user