mirror of https://github.com/vuejs/core.git
fix(v-model): fix trim modifier on events with non-string args ( (#5770)
fix #5765
This commit is contained in:
parent
bb06819d83
commit
018b850399
|
@ -386,6 +386,28 @@ describe('component: emit', () => {
|
||||||
expect(fn2).toHaveBeenCalledWith(1)
|
expect(fn2).toHaveBeenCalledWith(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('only trim string parameter when work with v-model on component', () => {
|
||||||
|
const Foo = defineComponent({
|
||||||
|
render() {},
|
||||||
|
created() {
|
||||||
|
this.$emit('update:modelValue', ' foo ', { bar: ' bar ' })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const fn = jest.fn()
|
||||||
|
const Comp = () =>
|
||||||
|
h(Foo, {
|
||||||
|
modelValue: null,
|
||||||
|
modelModifiers: { trim: true },
|
||||||
|
'onUpdate:modelValue': fn
|
||||||
|
})
|
||||||
|
|
||||||
|
render(h(Comp), nodeOps.createElement('div'))
|
||||||
|
|
||||||
|
expect(fn).toHaveBeenCalledTimes(1)
|
||||||
|
expect(fn).toHaveBeenCalledWith('foo', { bar: ' bar ' })
|
||||||
|
})
|
||||||
|
|
||||||
test('isEmitListener', () => {
|
test('isEmitListener', () => {
|
||||||
const options = {
|
const options = {
|
||||||
click: null,
|
click: null,
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
isArray,
|
isArray,
|
||||||
isFunction,
|
isFunction,
|
||||||
isObject,
|
isObject,
|
||||||
|
isString,
|
||||||
isOn,
|
isOn,
|
||||||
toNumber,
|
toNumber,
|
||||||
UnionToIntersection
|
UnionToIntersection
|
||||||
|
@ -122,7 +123,7 @@ export function emit(
|
||||||
}Modifiers`
|
}Modifiers`
|
||||||
const { number, trim } = props[modifiersKey] || EMPTY_OBJ
|
const { number, trim } = props[modifiersKey] || EMPTY_OBJ
|
||||||
if (trim) {
|
if (trim) {
|
||||||
args = rawArgs.map(a => a.trim())
|
args = rawArgs.map(a => isString(a) ? a.trim() : a)
|
||||||
}
|
}
|
||||||
if (number) {
|
if (number) {
|
||||||
args = rawArgs.map(toNumber)
|
args = rawArgs.map(toNumber)
|
||||||
|
|
Loading…
Reference in New Issue