diff --git a/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js b/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js index 2be66a16fece6d1b19967f75cf2e928a767794f7..9f8a483ff95350e46efd5f444c44442f33de748f 100644 --- a/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js +++ b/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js @@ -128,7 +128,8 @@ module.exports = function generateComponent (compilation) { } if (name.endsWith('.wxss')) { // 移除部分含有错误引用的 wxss 文件 - const origSource = assets[name].source().trim() + let origSource = assets[name].source() + origSource = origSource.trim ? origSource.trim() : '' const result = origSource.match(/^@import ["'](.+?)["']$/) if (result) { const wxssPath = path.join(path.dirname(name), result[1]) diff --git a/src/core/runtime/event-bus.js b/src/core/runtime/event-bus.js index c94c4cb05a9ed27d34359d535414e3191af3b4d8..0cd25064ef9c6d52620b0bb1af4e2f6873ef100d 100644 --- a/src/core/runtime/event-bus.js +++ b/src/core/runtime/event-bus.js @@ -1,10 +1,6 @@ import Vue from 'vue' const getEmitter = (function () { - if (typeof getUniEmitter === 'function') { - /* eslint-disable no-undef */ - return getUniEmitter - } let Emitter return function getUniEmitter () { if (!Emitter) { diff --git a/src/core/runtime/wrapper/util.js b/src/core/runtime/wrapper/util.js index d1c8e6ba9727135109ddf5167fcdbe44809f8b4d..35c0fd93bfa3abbcc2843b16ec4ef7175a672139 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] } -} +}