Browse Source

support .trim modifier on v-model

dev
Evan You 9 years ago
parent
commit
ad00f3d42a
  1. 8
      src/compiler/codegen/directives/model.js

8
src/compiler/codegen/directives/model.js

@ -35,14 +35,14 @@ function genRadioModel (el, value) {
function genDefaultModel (el, value, modifiers) {
const type = el.attrsMap.type
const lazy = modifiers && modifiers.lazy
const number = modifiers && modifiers.number
const { lazy, number, trim } = modifiers || {}
const event = lazy ? 'change' : 'input'
const needCompositionGuard = !lazy && type !== 'range'
const valueExpression = `$event.target.value${trim ? '.trim()' : ''}`
let code = number || type === 'number'
? `${value}=Number($event.target.value)`
: `${value}=$event.target.value`
? `${value}=Number(${valueExpression})`
: `${value}=${valueExpression}`
if (needCompositionGuard) {
code = `if($event.target.composing)return;${code}`
}

Loading…
Cancel
Save