From f299185cbb4464110f44d44d2149c991cd456752 Mon Sep 17 00:00:00 2001 From: ruochuan Date: Thu, 29 Aug 2024 00:05:03 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0=20taro=20events=20?= =?UTF-8?q?=E6=96=87=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/taro/events/README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/taro/events/README.md b/docs/taro/events/README.md index b52e350f..220bc817 100644 --- a/docs/taro/events/README.md +++ b/docs/taro/events/README.md @@ -598,23 +598,27 @@ export class TaroHooks = any> extends Events { } ``` -### 8.1 tap 实现 +### 8.1 tap 方法 - 监听事件 ```ts tap> (hookName: K, callback: T[K] | T[K][]) { const hooks = this.hooks const { type, initial } = hooks[hookName] if (type === HOOK_TYPE.SINGLE) { + // 单个类型的hook,则取消监听事件,重新监听事件 this.off(hookName) this.on(hookName, isFunction(callback) ? callback : callback[callback.length - 1]) } else { + // 不是,则取消监听指定回调函数的事件,重新监听一个或多个事件 initial && this.off(hookName, initial) this.tapOneOrMany(hookName, callback) } } ``` -### 8.2 call 实现 +`tap` 方法是监听事件,`hook`类型是`SINGLE`类型时,直接取消,重新监听。不是`SINGLE`类型时,则取消监听指定回调函数的事件,重新监听一个或多个事件。 + +### 8.2 call 方法 - 触发事件 ```ts call> (hookName: K, ...rest: Parameters): ReturnType | undefined {