From 661d880075f6e5280884a91fd9ac949064cc10d5 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 24 Feb 2017 12:17:59 -0500 Subject: [PATCH] fix component v-model with "value" binding expression (fix #5002) --- src/compiler/directives/model.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/compiler/directives/model.js b/src/compiler/directives/model.js index ea7985ca..e082631e 100644 --- a/src/compiler/directives/model.js +++ b/src/compiler/directives/model.js @@ -10,17 +10,22 @@ export function genComponentModel ( ): ?boolean { const { number, trim } = modifiers || {} - let valueExpression = 'value' + const baseValueExpression = '$$v' + let valueExpression = baseValueExpression if (trim) { - valueExpression = `(typeof value === 'string' ? value.trim() : value)` + valueExpression = + `(typeof ${baseValueExpression} === 'string'` + + `? ${baseValueExpression}.trim()` + + `: ${baseValueExpression})` } if (number) { valueExpression = `_n(${valueExpression})` } + const assignment = genAssignmentCode(value, valueExpression) el.model = { value: `(${value})`, - callback: `function (value) {${genAssignmentCode(value, valueExpression)}}` + callback: `function (${baseValueExpression}) {${assignment}}` } }