Przeglądaj źródła

do not unregister ref if parent is being destroyed

Evan You 10 lat temu
rodzic
commit
9719cfa64c
1 zmienionych plików z 8 dodań i 8 usunięć
  1. 8 8
      src/instance/lifecycle.js

+ 8 - 8
src/instance/lifecycle.js

@@ -133,6 +133,14 @@ exports._destroy = function (remove, deferCleanup) {
   var parent = this.$parent
   if (parent && !parent._isBeingDestroyed) {
     parent.$children.$remove(this)
+    // unregister ref
+    var ref = this.$options._ref
+    if (ref) {
+      var scope = this._scope || this._context
+      if (scope.$refs[ref] === this) {
+        scope.$refs[ref] = null
+      }
+    }
   }
   // remove self from owner fragment
   if (this._frag) {
@@ -156,14 +164,6 @@ exports._destroy = function (remove, deferCleanup) {
   while (i--) {
     this._watchers[i].teardown()
   }
-  // unregister ref
-  var ref = this.$options._ref
-  if (ref) {
-    var scope = this._scope || this._context
-    if (scope.$refs[ref] === this) {
-      scope.$refs[ref] = null
-    }
-  }
   // remove reference to self on $el
   if (this.$el) {
     this.$el.__vue__ = null