Skip to content

Commit

Permalink
fix #539
Browse files Browse the repository at this point in the history
  • Loading branch information
mzh1994s committed Jan 15, 2021
1 parent fdec35a commit 7c83600
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 7c83600

Please sign in to comment.