mirror of
https://github.com/vuejs/vue.git
synced 2024-11-21 20:28:54 +00:00
adjust v-model on component sync mechanism (fix #3179)
This commit is contained in:
parent
1b60a88ee1
commit
6cf19291be
@ -48,7 +48,7 @@
|
||||
.select2({ data: this.options })
|
||||
// emit event on change.
|
||||
.on('change', function () {
|
||||
vm.$emit('input', mockEvent(this.value))
|
||||
vm.$emit('input', this.value)
|
||||
})
|
||||
},
|
||||
watch: {
|
||||
@ -66,16 +66,6 @@
|
||||
}
|
||||
})
|
||||
|
||||
// mock an event because the v-model binding expects
|
||||
// event.target.value
|
||||
function mockEvent (value) {
|
||||
return {
|
||||
target: {
|
||||
value: value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var vm = new Vue({
|
||||
el: '#el',
|
||||
template: '#demo-template',
|
||||
|
@ -98,15 +98,18 @@ function genDefaultModel (
|
||||
const { lazy, number, trim } = modifiers || {}
|
||||
const event = lazy ? 'change' : 'input'
|
||||
const needCompositionGuard = !lazy && type !== 'range'
|
||||
const isNative = el.tag === 'input' || el.tag === 'textarea'
|
||||
|
||||
const valueExpression = `$event.target.value${trim ? '.trim()' : ''}`
|
||||
const valueExpression = isNative
|
||||
? `$event.target.value${trim ? '.trim()' : ''}`
|
||||
: `$event`
|
||||
let code = number || type === 'number'
|
||||
? `${value}=_n(${valueExpression})`
|
||||
: `${value}=${valueExpression}`
|
||||
if (needCompositionGuard) {
|
||||
if (isNative && needCompositionGuard) {
|
||||
code = `if($event.target.composing)return;${code}`
|
||||
}
|
||||
addProp(el, 'value', `_s(${value})`)
|
||||
addProp(el, 'value', isNative ? `_s(${value})` : `(${value})`)
|
||||
addHandler(el, event, code)
|
||||
if (needCompositionGuard) {
|
||||
// need runtime directive code to help with composition events
|
||||
|
@ -21,7 +21,7 @@ describe('Directive v-model component', () => {
|
||||
methods: {
|
||||
onInput (e) {
|
||||
// something validate ...
|
||||
this.$emit('input', e)
|
||||
this.$emit('input', e.target.value)
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
|
Loading…
Reference in New Issue
Block a user