提交 21adee5c 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat(event-bus): 补充对象字面量参数示例

上级 b4d1f84e
...@@ -52,6 +52,14 @@ describe('event-bus', () => { ...@@ -52,6 +52,14 @@ describe('event-bus', () => {
expect(l3).toBe(0) expect(l3).toBe(0)
}) })
it('emit object params', async () => {
await page.callMethod('onObj')
await page.callMethod('emitWithObj')
const objArg = await page.data('objArg')
expect(objArg.a).toBe(1)
expect(objArg.b).toBe(2)
})
it('off-all', async () => { it('off-all', async () => {
await page.callMethod('clear') await page.callMethod('clear')
await page.callMethod('on') await page.callMethod('on')
......
...@@ -14,6 +14,12 @@ ...@@ -14,6 +14,12 @@
<view> <view>
<view v-for="(item, index) in log" :key="index">{{ item }}</view> <view v-for="(item, index) in log" :key="index">{{ item }}</view>
</view> </view>
<button @click="onObj">开始监听 obj 参数</button>
<button @click="emitWithObj">触发监听 obj 参数</button>
<view class="box">
<text>接收到的 obj 参数:</text>
<text>{{JSON.stringify(objArg)}}</text>
</view>
</view> </view>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
...@@ -26,6 +32,7 @@ ...@@ -26,6 +32,7 @@
data() { data() {
return { return {
log: [] as string[], log: [] as string[],
objArg: {},
} }
}, },
methods: { methods: {
...@@ -41,6 +48,11 @@ ...@@ -41,6 +48,11 @@
on2() { on2() {
uni.$on('test', this.fn2) uni.$on('test', this.fn2)
}, },
onObj() {
uni.$on('test-obj', (res: UTSJSONObject) => {
this.objArg = res
})
},
once() { once() {
uni.$once('test', this.fn) uni.$once('test', this.fn)
}, },
...@@ -53,6 +65,9 @@ ...@@ -53,6 +65,9 @@
emit() { emit() {
uni.$emit('test', 'msg:' + Date.now()) uni.$emit('test', 'msg:' + Date.now())
}, },
emitWithObj() {
uni.$emit('test-obj', { a: 1, b: 2 })
},
clear() { clear() {
this.log.length = 0 this.log.length = 0
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册