mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-05 05:27:59 +08:00
parent
8567e7dced
commit
0163a6fe53
@ -1,6 +1,6 @@
|
||||
/* @flow */
|
||||
|
||||
import { extend } from 'shared/util'
|
||||
import { extend, toNumber } from 'shared/util'
|
||||
|
||||
function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
|
||||
if (!oldVnode.data.domProps && !vnode.data.domProps) {
|
||||
@ -35,7 +35,10 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
|
||||
elm._value = cur
|
||||
// avoid resetting cursor position when value is the same
|
||||
const strCur = cur == null ? '' : String(cur)
|
||||
if (elm.value !== strCur && !elm.composing && document.activeElement !== elm) {
|
||||
if (!elm.composing && (
|
||||
(document.activeElement !== elm && elm.value !== strCur) ||
|
||||
isValueChanged(vnode, strCur)
|
||||
)) {
|
||||
elm.value = strCur
|
||||
}
|
||||
} else {
|
||||
@ -44,6 +47,29 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
|
||||
}
|
||||
}
|
||||
|
||||
function isValueChanged (vnode: VNodeWithData, newVal: string): boolean {
|
||||
const value = vnode.elm.value
|
||||
const modifiers = getModelModifier(vnode)
|
||||
if ((modifiers && modifiers.number) || vnode.elm.type === 'number') {
|
||||
return toNumber(value) !== toNumber(newVal)
|
||||
}
|
||||
if (modifiers && modifiers.trim) {
|
||||
return value.trim() !== newVal.trim()
|
||||
}
|
||||
return value !== newVal
|
||||
}
|
||||
|
||||
function getModelModifier (vnode: VNodeWithData): ?ASTModifiers {
|
||||
const directives = vnode.data.directives
|
||||
if (!directives) return
|
||||
for (let i = 0, directive; i < directives.length; i++) {
|
||||
directive = directives[i]
|
||||
if (directive.name === 'model') {
|
||||
return directive.modifiers
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
create: updateDOMProps,
|
||||
update: updateDOMProps
|
||||
|
Loading…
Reference in New Issue
Block a user