Skip to content

Commit

Permalink
refactor: small tweak to vuejs#6910
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 authored and hefeng committed Jan 25, 2019
1 parent 507e0ec commit b9f5241
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/platforms/web/runtime/directives/model.js
Expand Up @@ -5,9 +5,8 @@

import { isTextInputType } from 'web/util/element'
import { looseEqual, looseIndexOf } from 'shared/util'
import { warn, isAndroid, isIE9, isIE, isEdge } from 'core/util/index'
import { mergeVNodeHook } from 'core/vdom/helpers/index'
import { emptyNode } from 'core/vdom/patch'
import { warn, isAndroid, isIE9, isIE, isEdge } from 'core/util/index'

/* istanbul ignore if */
if (isIE9) {
Expand All @@ -24,7 +23,7 @@ const directive = {
inserted (el, binding, vnode, oldVnode) {
if (vnode.tag === 'select') {
// #6903
if (oldVnode !== emptyNode && !hasDirective(oldVnode, 'model')) {
if (oldVnode.elm && !oldVnode.elm._vOptions) {
mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'postpatch', () => {
directive.componentUpdated(el, binding, vnode)
})
Expand All @@ -51,6 +50,7 @@ const directive = {
}
}
},

componentUpdated (el, binding, vnode) {
if (vnode.tag === 'select') {
setSelected(el, binding, vnode.context)
Expand Down Expand Up @@ -146,10 +146,4 @@ function trigger (el, type) {
el.dispatchEvent(e)
}

function hasDirective (vnode, dirname) {
return vnode.data &&
vnode.data.directives &&
vnode.data.directives.some(dir => dir.name === dirname)
}

export default directive

0 comments on commit b9f5241

Please sign in to comment.