fix(v-model): fix case where .trim and .number modifiers are used together (#5842)

fix #5839
This commit is contained in:
小刘(liulinboyi)
2022-05-13 07:52:16 +08:00
committed by GitHub
parent a3881299e9
commit 71066b5afe
4 changed files with 60 additions and 3 deletions

View File

@@ -355,6 +355,37 @@ describe('component: emit', () => {
expect(fn2).toHaveBeenCalledWith('two')
})
test('.trim and .number modifiers should work with v-model on component', () => {
const Foo = defineComponent({
render() {},
created() {
this.$emit('update:modelValue', ' +01.2 ')
this.$emit('update:foo', ' 1 ')
}
})
const fn1 = jest.fn()
const fn2 = jest.fn()
const Comp = () =>
h(Foo, {
modelValue: null,
modelModifiers: { trim: true, number: true },
'onUpdate:modelValue': fn1,
foo: null,
fooModifiers: { trim: true, number: true },
'onUpdate:foo': fn2
})
render(h(Comp), nodeOps.createElement('div'))
expect(fn1).toHaveBeenCalledTimes(1)
expect(fn1).toHaveBeenCalledWith(1.2)
expect(fn2).toHaveBeenCalledTimes(1)
expect(fn2).toHaveBeenCalledWith(1)
})
test('isEmitListener', () => {
const options = {
click: null,

View File

@@ -122,7 +122,8 @@ export function emit(
const { number, trim } = props[modifiersKey] || EMPTY_OBJ
if (trim) {
args = rawArgs.map(a => a.trim())
} else if (number) {
}
if (number) {
args = rawArgs.map(toNumber)
}
}