Skip to content

Commit 29d6e33

Browse files
committed
simplify value change check for v-model modifiers
1 parent 612d321 commit 29d6e33

File tree

2 files changed

+14
-25
lines changed

2 files changed

+14
-25
lines changed

src/platforms/web/runtime/directives/model.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ export default {
4040
if (isIE || isEdge) {
4141
setTimeout(cb, 0)
4242
}
43-
} else if (
44-
(vnode.tag === 'textarea' || el.type === 'text') &&
45-
!binding.modifiers.lazy
46-
) {
47-
if (!isAndroid) {
48-
el.addEventListener('compositionstart', onCompositionStart)
49-
el.addEventListener('compositionend', onCompositionEnd)
50-
}
51-
/* istanbul ignore if */
52-
if (isIE9) {
53-
el.vmodel = true
43+
} else if (vnode.tag === 'textarea' || el.type === 'text') {
44+
el._vModifiers = binding.modifiers
45+
if (!binding.modifiers.lazy) {
46+
if (!isAndroid) {
47+
el.addEventListener('compositionstart', onCompositionStart)
48+
el.addEventListener('compositionend', onCompositionEnd)
49+
}
50+
/* istanbul ignore if */
51+
if (isIE9) {
52+
el.vmodel = true
53+
}
5454
}
5555
}
5656
},

src/platforms/web/runtime/modules/dom-props.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
3636
// avoid resetting cursor position when value is the same
3737
const strCur = cur == null ? '' : String(cur)
3838
if (!elm.composing && (
39-
(document.activeElement !== elm && elm.value !== strCur) ||
40-
isValueChanged(vnode, strCur)
39+
(document.activeElement !== elm && elm.value !== strCur) ||
40+
isValueChanged(vnode, strCur)
4141
)) {
4242
elm.value = strCur
4343
}
@@ -49,7 +49,7 @@ function updateDOMProps (oldVnode: VNodeWithData, vnode: VNodeWithData) {
4949

5050
function isValueChanged (vnode: VNodeWithData, newVal: string): boolean {
5151
const value = vnode.elm.value
52-
const modifiers = getModelModifier(vnode)
52+
const modifiers = vnode.elm._vModifiers // injected by v-model runtime
5353
if ((modifiers && modifiers.number) || vnode.elm.type === 'number') {
5454
return toNumber(value) !== toNumber(newVal)
5555
}
@@ -59,17 +59,6 @@ function isValueChanged (vnode: VNodeWithData, newVal: string): boolean {
5959
return value !== newVal
6060
}
6161

62-
function getModelModifier (vnode: VNodeWithData): ?ASTModifiers {
63-
const directives = vnode.data.directives
64-
if (!directives) return
65-
for (let i = 0, directive; i < directives.length; i++) {
66-
directive = directives[i]
67-
if (directive.name === 'model') {
68-
return directive.modifiers
69-
}
70-
}
71-
}
72-
7362
export default {
7463
create: updateDOMProps,
7564
update: updateDOMProps

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy