瀏覽代碼

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

Evan You 11 年之前
父節點
當前提交
e63eaac722
共有 2 個文件被更改,包括 5 次插入2 次删除
  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)
       })