Просмотр исходного кода

destroy component after leaving transition

Evan You 11 лет назад
Родитель
Сommit
add1c73717
1 измененных файлов с 16 добавлено и 7 удалено
  1. 16 7
      src/directives/component.js

+ 16 - 7
src/directives/component.js

@@ -108,21 +108,30 @@ module.exports = {
    */
 
   unbuild: function (remove) {
-    if (!this.childVM) {
+    var child = this.childVM
+    if (!child) {
       return
     }
     if (this.keepAlive) {
       if (remove) {
-        this.childVM.$remove()
+        child.$remove()
       }
     } else {
-      this.childVM.$destroy(remove)
-      if (this.parentDirs) {
-        var i = this.parentDirs.length
-        while (i--) {
-          this.parentDirs[i]._teardown()
+      var parentDirs = this.parentDirs
+      var destroy = function () {
+        child.$destroy()
+        if (parentDirs) {
+          var i = parentDirs.length
+          while (i--) {
+            parentDirs[i]._teardown()
+          }
         }
       }
+      if (remove) {
+        child.$remove(destroy)
+      } else {
+        destroy()
+      }
     }
     this.childVM = null
   },