提交 87191113 编写于 作者: Q qiang

fix: 修复组件嵌套时解构插槽内事件报错的问题 question/99063

上级 b9521c5b
......@@ -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]
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册