fix transition remove

This commit is contained in:
Evan You 2016-04-21 02:45:14 -04:00
parent 050395408a
commit aaa334d08f
2 changed files with 22 additions and 18 deletions

View File

@ -1,5 +1,5 @@
import { isIE9 } from '../util/index'
import { beforeEnter, onLeave } from '../vdom-web/modules/transition'
import { enter, leave } from '../vdom-web/modules/transition'
export default {
bind (el, value) {
@ -12,10 +12,10 @@ export default {
: vnode.data.transition
if (!isIE9 && transition != null) {
if (value) {
beforeEnter(null, vnode)
enter(vnode)
el.style.display = ''
} else {
onLeave(vnode, () => {
leave(vnode, () => {
el.style.display = 'none'
})
}

View File

@ -29,7 +29,7 @@ function nextFrame (fn) {
})
}
export function beforeEnter (_, vnode) {
export function enter (vnode) {
const el = vnode.elm
// call leave callback now
if (el._leaveCb) {
@ -84,7 +84,7 @@ export function beforeEnter (_, vnode) {
}
}
export function onLeave (vnode, rm) {
export function leave (vnode, rm) {
const el = vnode.elm
// call enter callback now
if (el._enterCb) {
@ -235,24 +235,28 @@ function once (fn) {
}
}
function guardHook (hook, getVnode) {
return function guardedTransitionHook (_, __) {
const vnode = getVnode(_, __)
function shouldSkipTransition (vnode) {
return (
// if this is a component root node and the compoennt's
// parent container node also has transition, skip.
if (vnode.parent && vnode.parent.data.transition) {
return
}
(vnode.parent && vnode.parent.data.transition) ||
// if the element has v-show, let the runtime directive
// call the hooks instead
if (vnode.data.show) {
return
}
hook(_, __)
}
vnode.data.show
)
}
export default !transitionEndEvent ? {} : {
create: guardHook(beforeEnter, (_, vnode) => vnode),
remove: guardHook(onLeave, vnode => vnode)
create: function (_, vnode) {
if (!shouldSkipTransition(vnode)) {
enter(vnode)
}
},
remove: function (vnode, rm) {
if (!shouldSkipTransition(vnode)) {
leave(vnode, rm)
} else {
rm()
}
}
}