fix: sort vnode not work (#6100)

This commit is contained in:
neverland 2020-04-20 19:33:28 +08:00 committed by GitHub
parent 3188b4d25b
commit 177ef4d736
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,17 +18,16 @@ function flattenVNodes(vnodes: VNode[]) {
}
type VueInstance = {
_vnode: VNode;
$vnode: VNode;
};
// sort children instances by vnodes order
export function sortChildren(children: VueInstance[], parent: VueInstance) {
// null on SSR
if (!parent._vnode) {
const { componentOptions } = parent.$vnode;
if (!componentOptions || !componentOptions.children) {
return;
}
const vnodes = flattenVNodes(parent._vnode.children!);
const vnodes = flattenVNodes(componentOptions.children);
children.sort((a, b) => vnodes.indexOf(a.$vnode) - vnodes.indexOf(b.$vnode));
}