From ad00f3d42acbd1519862b6f9461ff626e0cbbbd1 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 22 Apr 2016 15:54:02 -0400 Subject: [PATCH] support .trim modifier on v-model --- src/compiler/codegen/directives/model.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/codegen/directives/model.js b/src/compiler/codegen/directives/model.js index 6c659fbd..75249aaf 100644 --- a/src/compiler/codegen/directives/model.js +++ b/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}` }