From 871911137822c500f1e2d648218c5a5d59db510a Mon Sep 17 00:00:00 2001 From: qiang Date: Mon, 13 Jul 2020 21:19:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=B5=8C=E5=A5=97=E6=97=B6=E8=A7=A3=E6=9E=84=E6=8F=92=E6=A7=BD?= =?UTF-8?q?=E5=86=85=E4=BA=8B=E4=BB=B6=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20question/99063?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/runtime/wrapper/util.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/core/runtime/wrapper/util.js b/src/core/runtime/wrapper/util.js index d1c8e6ba9..35c0fd93b 100644 --- a/src/core/runtime/wrapper/util.js +++ b/src/core/runtime/wrapper/util.js @@ -9,8 +9,8 @@ import { export const PAGE_EVENT_HOOKS = [ 'onPullDownRefresh', - 'onReachBottom', - 'onAddToFavorites', + 'onReachBottom', + 'onAddToFavorites', 'onShareTimeline', 'onShareAppMessage', 'onPageScroll', @@ -471,6 +471,15 @@ function isMatchEventType (eventType, optType) { ) } +function getContextVm (vm) { + let $parent = vm.$parent + // 父组件是 scoped slots 或者其他自定义组件时继续查找 + while ($parent && $parent.$parent && ($parent.$options.generic || $parent.$parent.$options.generic || $parent.$scope._$vuePid)) { + $parent = $parent.$parent + } + return $parent && $parent.$parent +} + export function handleEvent (event) { event = wrapper(event) @@ -503,12 +512,8 @@ export function handleEvent (event) { const methodName = eventArray[0] if (methodName) { let handlerCtx = this.$vm - if ( - handlerCtx.$options.generic && - handlerCtx.$parent && - handlerCtx.$parent.$parent - ) { // mp-weixin,mp-toutiao 抽象节点模拟 scoped slots - handlerCtx = handlerCtx.$parent.$parent + if (handlerCtx.$options.generic) { // mp-weixin,mp-toutiao 抽象节点模拟 scoped slots + handlerCtx = getContextVm(handlerCtx) || handlerCtx } if (methodName === '$emit') { handlerCtx.$emit.apply(handlerCtx, @@ -552,4 +557,4 @@ export function handleEvent (event) { ) { return ret[0] } -} +} -- GitLab