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

fix wait-for with keep-alive (fix #1150)

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

+ 16 - 7
src/directives/component.js

@@ -129,8 +129,9 @@ module.exports = {
             }
             }
           }
           }
         }
         }
-        var newComponent = this.build(options)
-        if (!waitFor) {
+        var cached = this.getCached()
+        var newComponent = cached || this.build(options)
+        if (!waitFor || cached) {
           this.transition(newComponent, cb)
           this.transition(newComponent, cb)
         }
         }
       }, this))
       }, this))
@@ -174,11 +175,9 @@ module.exports = {
    */
    */
 
 
   build: function (extraOptions) {
   build: function (extraOptions) {
-    if (this.keepAlive) {
-      var cached = this.cache[this.Component.cid]
-      if (cached) {
-        return cached
-      }
+    var cached = this.getCached()
+    if (cached) {
+      return cached
     }
     }
     if (this.Component) {
     if (this.Component) {
       // default options
       // default options
@@ -205,6 +204,16 @@ module.exports = {
     }
     }
   },
   },
 
 
+  /**
+   * Try to get a cached instance of the current component.
+   *
+   * @return {Vue|undefined}
+   */
+
+  getCached: function () {
+    return this.keepAlive && this.cache[this.Component.cid]
+  },
+
   /**
   /**
    * Teardown the current child, but defers cleanup so
    * Teardown the current child, but defers cleanup so
    * that we can separate the destroy and removal steps.
    * that we can separate the destroy and removal steps.