mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-04 13:07:40 +08:00
fix .trim modifier when v-model is used on custom component (fix #4204)
This commit is contained in:
parent
77497931e0
commit
3e8ac270a8
@ -123,7 +123,7 @@ function genDefaultModel (
|
||||
|
||||
let valueExpression = isNative
|
||||
? `$event.target.value${trim ? '.trim()' : ''}`
|
||||
: `$event`
|
||||
: trim ? `(typeof $event === 'string' ? $event.trim() : $event)` : `$event`
|
||||
valueExpression = number || type === 'number'
|
||||
? `_n(${valueExpression})`
|
||||
: valueExpression
|
||||
|
@ -51,4 +51,55 @@ describe('Directive v-model component', () => {
|
||||
vm.$destroy()
|
||||
}).then(done)
|
||||
})
|
||||
|
||||
it('modifier: .lazy', () => {
|
||||
const vm = new Vue({
|
||||
template: `<div><my-input ref="input" v-model.lazy="text"></my-input></div>`,
|
||||
data: { text: 'foo' },
|
||||
components: {
|
||||
'my-input': {
|
||||
template: '<input>'
|
||||
}
|
||||
}
|
||||
}).$mount()
|
||||
expect(vm.text).toBe('foo')
|
||||
vm.$refs.input.$emit('input', 'bar')
|
||||
expect(vm.text).toBe('foo')
|
||||
vm.$refs.input.$emit('change', 'bar')
|
||||
expect(vm.text).toBe('bar')
|
||||
})
|
||||
|
||||
it('modifier: .number', () => {
|
||||
const vm = new Vue({
|
||||
template: `<div><my-input ref="input" v-model.number="text"></my-input></div>`,
|
||||
data: { text: 'foo' },
|
||||
components: {
|
||||
'my-input': {
|
||||
template: '<input>'
|
||||
}
|
||||
}
|
||||
}).$mount()
|
||||
expect(vm.text).toBe('foo')
|
||||
vm.$refs.input.$emit('input', 'bar')
|
||||
expect(vm.text).toBe('bar')
|
||||
vm.$refs.input.$emit('input', '123')
|
||||
expect(vm.text).toBe(123)
|
||||
})
|
||||
|
||||
it('modifier: .trim', () => {
|
||||
const vm = new Vue({
|
||||
template: `<div><my-input ref="input" v-model.trim="text"></my-input></div>`,
|
||||
data: { text: 'foo' },
|
||||
components: {
|
||||
'my-input': {
|
||||
template: '<input>'
|
||||
}
|
||||
}
|
||||
}).$mount()
|
||||
expect(vm.text).toBe('foo')
|
||||
vm.$refs.input.$emit('input', ' bar ')
|
||||
expect(vm.text).toBe('bar')
|
||||
vm.$refs.input.$emit('input', ' foo o ')
|
||||
expect(vm.text).toBe('foo o')
|
||||
})
|
||||
})
|
||||
|
@ -11,9 +11,6 @@ describe('compile v-model', () => {
|
||||
expect(errors).toEqual([])
|
||||
})
|
||||
|
||||
it('should compile into render functions without runtime model directive', () => {
|
||||
})
|
||||
|
||||
it('should compile other component with whole $event as the value', () => {
|
||||
const { render, staticRenderFns, errors } = compile(`<div><foo v-model="x" /></div>`)
|
||||
expect(render).not.toBeUndefined()
|
||||
|
Loading…
Reference in New Issue
Block a user