Skip to content

Commit

Permalink
Merge pull request #548 from mzh1994s/fix-root-async-component
Browse files Browse the repository at this point in the history
fix #539
  • Loading branch information
errorrik committed Feb 17, 2021
2 parents fdec35a + 7c83600 commit 36e1939
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/view/async-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,22 @@ AsyncComponent.prototype.onload = function (ComponentClass) {
var component = new ComponentClass(this.options);
component.attach(this.el.parentNode, this.el);

var parentChildren = this.options.parent.children;
if (this.parentIndex == null || parentChildren[this.parentIndex] !== this) {
each(parentChildren, function (child, index) {
if (child instanceof AsyncComponent) {
child.parentIndex = index;
}
});
// 如果异步组件时root节点,则更新为root节点
if(this.options.parent._rootNode === this){
this.options.parent._rootNode = component;
} else {
// 原本的逻辑
var parentChildren = this.options.parent.children;
if (this.parentIndex == null || parentChildren[this.parentIndex] !== this) {
each(parentChildren, function (child, index) {
if (child instanceof AsyncComponent) {
child.parentIndex = index;
}
});
}

parentChildren[this.parentIndex] = component;
}

parentChildren[this.parentIndex] = component;
}

this.dispose();
Expand Down

0 comments on commit 36e1939

Please sign in to comment.