mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-04 21:17:55 +08:00
fix component v-model with "value" binding expression (fix #5002)
This commit is contained in:
parent
394679fc70
commit
661d880075
@ -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}}`
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user