extend(Vue.options.components,platformComponents)
transition
export default{
name:'transition',
props:transitionProps,
abstract:true,
render(h){
let children = this.$slots.default
if(!children){
return
}
children = children.filter(isNotTextNode)
if(!children.length){
return
}
...
const rawChild = children[0]
if(hasParentTransition(rawChild)){
return rawChild
}
const child = getRealChild(rawChild)
if(!child){
return rawChild
}
if(this._leaving){
return placeholder(h,rawChild)
}
...
const data = (child.data || (child.data = {})).transition = extractTransitionData(this)
const oldRawChild = this._vnode
const oldChild = getRealChild(oldRawChild)
if(child.data.directives && child.data.directives.some(isVShowDirective)){
child.data.show = true
}
if(oldChild && oldChild.data && !isSameChild(child,oldChild) && !isAsyncPlaceholder(oldChild) && !(oldChild.componentInstance && oldChild.componentInstance._vnode.isComment)){
const oldData = oldChid.data.transition = extend({},data)
if(mode === 'out-in'){
this._leaving = true
mergeVNodeHook(oldData,'afterLeave',() => {
this._leaving = false;
this.$forceUpdate()
})
return placeholder(h,rawChild)
}else if(mode === 'in-out'){
if(isAsyncPlaceholder(child)){
return oldRawChild
}
let delayedLeave
const performLeave = () => {delayedLeave()}
mergeVNodeHook(data,'afterEnter',performLeave)
mergeVNodeHook(data,'enterCancelled',performLeave)
mergeVNodeHook(data,'delayLeave',leave => {delayedLeave = leave})
}
}
return rawChild
}
}
transition-group
export default {
props,
beforMount(){
const update = this._update
this._update = (vnode,hydrating) => {
const restoreActiveInstance = setActiveInstance(this)
this.__patch__(this._vnode,this.kept,false,true)
this._vnode = this.kept
restoreActiveInstance()
update.call(this,vnode,hydrating)
}
},
render(h){
const tag = this.tag || this.$vnode.data.tag || 'span'
const map = Object.create(null)
const prevChildren = this.prevChildren = this.children
const rawChildren = this.$slots.default || []
const children = this.children = []
const transitionData = extractTransitionData(this)
for(let i = 0; i < rawChildren.length; i ++){
const c = rawChildren[i]
if(c.tag){
if(c.key !== null && String(c.key).indexOf('_vlist') !== 0){
children.push(c)
map[c.key] = c
(c.data || (c.data = {})).transition = transitionData
}else{
...
}
}
}
if(prevChildren){
const kept = []
const removed = []
for(let i = 0; i < prevChildren.length; i ++){
const c = prevChildren[i]
c.data.transition = transitionData
c.data.pos = c.elm.getBoundingClientRect()
if(map[c.key]){
kept.push(c)
}else{
removed.push(c)
}
}
this.kept = h(tag,null,kept)
this.removed = removed
}
return h(tag,null,children)
},
updated(){
const children = this.prevChildren
const moveClass = this.moveClass || ((this.name || 'v') + '-move')
if(!children.length || !this.hasMove(children[0].elm,moveClass)){
return
}
children.forEach(callPendingCbs)
children.forEach(recordPosition)
children.forEach(applyTranslation)
this._reflow = document.body.offsetHeight
children.forEach((c) => {
if(c.data.moved){
const el = c.elm
const s = el.style
addTransitionClass(el,moveClass)
s.transform = s.WebkitTransform = s.transitionDuration = ''
el.addEventListener(transitionEndEvent,el._moveCb = function cb(e){
if( e && e.target !== el){
return
}
if(!e || /transform$/.test(e.propertyName)){
el.removeEventListener(transitionEndEvent,cb)
el._moveCb = null
removeTransitionClass(el,moveClass)
}
})
}
})
}
}