Przeglądaj źródła

dynamic component transition

Evan You 10 lat temu
rodzic
commit
7b97d97e2f

+ 2 - 0
src/runtime/dom-backend/modules/transition.js

@@ -56,7 +56,9 @@ function beforeEnter (_, vnode) {
 }
 
 function onLeave (vnode, rm) {
+  console.log(vnode)
   const el = vnode.elm
+  if (!el) return
   // call enter callback now
   if (el._enterCb) {
     el._enterCb()

+ 4 - 1
src/runtime/instance/render.js

@@ -158,7 +158,7 @@ function resolveSlots (vm, children) {
   }
 }
 
-const keysToDiff = ['class', 'style', 'attrs', 'props', 'directives']
+const keysToDiff = ['class', 'style', 'attrs', 'props', 'directives', 'transition']
 function parentDataChanged (data, oldData) {
   let key, old, cur, i, l, j, k
   for (i = 0, l = keysToDiff.length; i < l; i++) {
@@ -236,6 +236,9 @@ function mergeParentData (vm, data, parentData) {
   if (parentData.directives) {
     data.directives = parentData.directives.concat(data.directives || [])
   }
+  if (parentData.transition != null) {
+    data.transition = parentData.transition
+  }
 }
 
 function updateProps (vm, data) {

+ 1 - 5
src/runtime/vdom/component.js

@@ -35,7 +35,7 @@ export default function Component (Ctor, data, parent, children) {
     }
   }
   // merge hooks on the placeholder node itself
-  const hook = { init, insert, prepatch, destroy }
+  const hook = { init, insert, prepatch }
   if (data.hook) {
     for (let key in data.hook) {
       let existing = hook[key]
@@ -91,10 +91,6 @@ function prepatch (oldVnode, vnode) {
   }
 }
 
-function destroy (vnode) {
-  vnode.data.child.$destroy()
-}
-
 function resolveAsyncComponent (factory, cb) {
   if (factory.resolved) {
     // cached

+ 5 - 1
src/runtime/vdom/patch.js

@@ -121,9 +121,13 @@ export default function createPatchFunction (backend) {
   function removeVnodes (parentElm, vnodes, startIdx, endIdx) {
     for (; startIdx <= endIdx; ++startIdx) {
       let i, listeners, rm
-      const ch = vnodes[startIdx]
+      let ch = vnodes[startIdx]
       if (isDef(ch)) {
         if (isDef(ch.tag)) {
+          if (isDef(i = ch.data) && isDef(i = i.child)) {
+            i.$destroy()
+            ch = i._vnode
+          }
           invokeDestroyHook(ch)
           listeners = cbs.remove.length + 1
           rm = createRmCb(getElm(ch), listeners)