From b794d41e5c0d427edde9452651118c5da1bae682 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Mon, 30 Dec 2019 19:11:34 +0800 Subject: [PATCH] fix(mp-weixin): findVmByVueId #1200 --- src/platforms/mp-weixin/runtime/wrapper/util.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/platforms/mp-weixin/runtime/wrapper/util.js b/src/platforms/mp-weixin/runtime/wrapper/util.js index 926f4d09e..079e7f58e 100644 --- a/src/platforms/mp-weixin/runtime/wrapper/util.js +++ b/src/platforms/mp-weixin/runtime/wrapper/util.js @@ -2,12 +2,15 @@ export const mocks = ['__route__', '__wxExparserNodeId__', '__wxWebviewId__'] export function findVmByVueId (vm, vuePid) { const $children = vm.$children - // 优先查找直属 - let parentVm = $children.find(childVm => childVm.$scope._$vueId === vuePid) - if (parentVm) { - return parentVm + // 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200) + for (let i = $children.length - 1; i >= 0; i--) { + const childVm = $children[i] + if (childVm.$scope._$vueId === vuePid) { + return childVm + } } // 反向递归查找 + let parentVm for (let i = $children.length - 1; i >= 0; i--) { parentVm = findVmByVueId($children[i], vuePid) if (parentVm) { -- GitLab