Parcourir la source

fix #474 $destroy removing self from parent, splice() missing argument

Evan You il y a 11 ans
Parent
commit
e63eaac722
2 fichiers modifiés avec 5 ajouts et 2 suppressions
  1. 1 1
      src/api/lifecycle.js
  2. 4 1
      test/unit/specs/api/lifecycle_spec.js

+ 1 - 1
src/api/lifecycle.js

@@ -73,7 +73,7 @@ exports.$destroy = function (remove) {
   var parent = this.$parent
   if (parent && !parent._isBeingDestroyed) {
     i = parent._children.indexOf(this)
-    parent._children.splice(i)
+    parent._children.splice(i, 1)
   }
   // destroy all children.
   if (this._children) {

+ 4 - 1
test/unit/specs/api/lifecycle_spec.js

@@ -201,8 +201,11 @@ if (_.inBrowser) {
       it('parent', function () {
         var parent = new Vue()
         var child = parent.$addChild()
-        expect(parent._children.length).toBe(1)
+        var child2 = parent.$addChild()
+        expect(parent._children.length).toBe(2)
         child.$destroy()
+        expect(parent._children.length).toBe(1)
+        child2.$destroy()
         expect(parent._children.length).toBe(0)
       })