fix component v-model with "value" binding expression (fix #5002)

This commit is contained in:
Evan You 2017-02-24 12:17:59 -05:00
parent 394679fc70
commit 661d880075

View File

@ -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}}`
}
}