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

fix(v-model): keep the same behavior as v-model with undefinedvalue with 2.x #1530

Merged
merged 2 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/runtime-dom/__tests__/directives/vModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('vModel', () => {

const input = root.querySelector('input')!
const data = root._vnode.component.data
expect(input.value).toEqual('')

input.value = 'foo'
triggerEvent('input', input)
Expand All @@ -57,6 +58,10 @@ describe('vModel', () => {
data.value = 'bar'
await nextTick()
expect(input.value).toEqual('bar')

data.value = undefined
await nextTick()
expect(input.value).toEqual('')
})

it('should work with multiple listeners', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-dom/src/directives/vModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const vModelText: ModelDirective<
HTMLInputElement | HTMLTextAreaElement
> = {
beforeMount(el, { value, modifiers: { lazy, trim, number } }, vnode) {
el.value = value
el.value = value == null ? '' : value
el._assign = getModelAssigner(vnode)
const castToNumber = number || el.type === 'number'
addEventListener(el, lazy ? 'change' : 'input', e => {
Expand Down Expand Up @@ -85,7 +85,7 @@ export const vModelText: ModelDirective<
return
}
}
el.value = value
el.value = value == null ? '' : value
}
}

Expand Down