2
2
3
3
import { extend , toNumber } from 'shared/util'
4
4
5
+ // check platforms/web/util/attrs.js acceptValue
6
+ declare type acceptValueElm = HTMLInputElement | HTMLSelectElement | HTMLOptionElement
7
+
5
8
function updateDOMProps ( oldVnode : VNodeWithData , vnode : VNodeWithData ) {
6
9
if ( ! oldVnode . data . domProps && ! vnode . data . domProps ) {
7
10
return
@@ -35,10 +38,7 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
35
38
elm . _value = cur
36
39
// avoid resetting cursor position when value is the same
37
40
const strCur = cur == null ? '' : String ( cur )
38
- if ( ! elm . composing && (
39
- ( document . activeElement !== elm && elm . value !== strCur ) ||
40
- isValueChanged ( vnode , strCur )
41
- ) ) {
41
+ if ( needUpdateValue ( elm , vnode , strCur ) ) {
42
42
elm . value = strCur
43
43
}
44
44
} else {
@@ -47,7 +47,20 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
47
47
}
48
48
}
49
49
50
- function isValueChanged ( vnode : VNodeWithData , newVal : string ) : boolean {
50
+ function needUpdateValue ( elm : acceptValueElm , vnode : VNodeWithData , checkVal : string ) : boolean {
51
+ // inputing
52
+ if ( elm . composing ) return false
53
+ if ( elm . tagName . toLowerCase ( ) === 'option' ) return true
54
+ if ( isDirty ( elm , checkVal ) ) return true
55
+ if ( isInputChanged ( vnode , checkVal ) ) return true
56
+ return false
57
+ }
58
+
59
+ function isDirty ( elm : acceptValueElm , checkVal : string ) : boolean {
60
+ return document . activeElement !== elm && elm . value !== checkVal
61
+ }
62
+
63
+ function isInputChanged ( vnode : VNodeWithData , newVal : string ) : boolean {
51
64
const value = vnode . elm . value
52
65
const modifiers = vnode . elm . _vModifiers // injected by v-model runtime
53
66
if ( ( modifiers && modifiers . number ) || vnode . elm . type === 'number' ) {
0 commit comments