diff --git a/pages/API/event-bus/event-bus.test.js b/pages/API/event-bus/event-bus.test.js
index f3aa542d21176af817e96614f99e0698dfacf540..0e5d377414be46f0a68198aa8ea48992ede8b04f 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 ab383fff1773c668f0e88926a2789089e8727ae0..99395dd7a3f618467ac006048dbbd8c0123031c2 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;
}
-
+