From b835bb24888db3ee150192ef10726de8f7c5ec3b Mon Sep 17 00:00:00 2001 From: roymondchen Date: Tue, 20 Sep 2022 15:20:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(core):=20=E5=A4=9A=E4=B8=AA=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E9=85=8D=E7=BD=AE=E5=90=8C=E4=B8=80=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E4=BC=9A=E5=AF=BC=E8=87=B4=E6=AD=A4=E4=BA=8B=E4=BB=B6=E5=A4=9A?= =?UTF-8?q?=E6=AC=A1=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #356 --- packages/core/src/App.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/core/src/App.ts b/packages/core/src/App.ts index 1e5f08d1..661a79a7 100644 --- a/packages/core/src/App.ts +++ b/packages/core/src/App.ts @@ -28,6 +28,7 @@ import { isCommonMethod, triggerCommonMethod, } from './events'; +import type Node from './Node'; import Page from './Page'; import { fillBackgroundImage, isNumber, style2Obj } from './utils'; @@ -207,11 +208,18 @@ class App extends EventEmitter { eventName = getCommonEventName(eventName, id); } - this.on(eventName, (fromCpt, ...args) => { + this.on(`${eventName}_${id}`, (fromCpt: Node, ...args) => { this.eventHandler(event, fromCpt, args); }); } + public emit(name: string | symbol, node: any, ...args: any[]): boolean { + if (typeof node.data === 'undefined') { + return super.emit(name, node, ...args); + } + return super.emit(`${String(name)}_${node.data.id}`, ...args); + } + public eventHandler(eventConfig: EventItemConfig, fromCpt: any, args: any[]) { if (!this.page) throw new Error('当前没有页面');