From f4686a314681428a75e16db245cb789e789c9bcf Mon Sep 17 00:00:00 2001
From: zhenyuWang <13641039885@163.com>
Date: Mon, 23 Sep 2024 12:04:39 +0800
Subject: [PATCH] =?UTF-8?q?feat(eventBus):=20=E8=A1=A5=E5=85=85=E8=BF=94?=
=?UTF-8?q?=E5=9B=9E=20id=20=E7=A4=BA=E4=BE=8B=E5=8F=8A=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pages/API/event-bus/event-bus.test.js | 9 +++++++++
pages/API/event-bus/event-bus.uvue | 16 +++++++++++++++-
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/pages/API/event-bus/event-bus.test.js b/pages/API/event-bus/event-bus.test.js
index f3aa542d..0e5d3774 100644
--- a/pages/API/event-bus/event-bus.test.js
+++ b/pages/API/event-bus/event-bus.test.js
@@ -77,4 +77,13 @@ describe('event-bus', () => {
const l3 = (await page.data()).log.length
expect(l3).toBe(0)
})
+ it('test return id', async () => {
+ await page.callMethod('clear')
+ expect((await page.data()).log.length).toBe(0)
+ await page.callMethod('testReturnId')
+ const logs = await page.data('log')
+ expect(logs.length).toBe(2)
+ expect(logs[0]).toBe('触发 test-return-id $on fn')
+ expect(logs[1]).toBe('触发 test-return-id $once fn')
+ })
})
diff --git a/pages/API/event-bus/event-bus.uvue b/pages/API/event-bus/event-bus.uvue
index ab383fff..99395dd7 100644
--- a/pages/API/event-bus/event-bus.uvue
+++ b/pages/API/event-bus/event-bus.uvue
@@ -20,6 +20,7 @@
接收到的 obj 参数:
{{JSON.stringify(objArg)}}
+
@@ -71,6 +72,19 @@
clear() {
this.log.length = 0
},
+ testReturnId(){
+ const id1 = uni.$on('test-return-id', this.fn)
+ uni.$emit('test-return-id', '触发 test-return-id $on fn')
+ uni.$off('test-return-id', id1)
+ uni.$emit('test-return-id', '触发 test-return-id $on fn')
+
+ uni.$once('test-return-id', this.fn)
+ uni.$emit('test-return-id', '触发 test-return-id $once fn')
+ uni.$emit('test-return-id', '触发 test-return-id $once fn')
+ const id2 = uni.$once('test-id', this.fn)
+ uni.$off('test-return-id', id2)
+ uni.$emit('test-return-id', '触发 test-return-id $once fn')
+ }
},
}
@@ -79,4 +93,4 @@
.box {
padding: 10px;
}
-
+
--
GitLab