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

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

上级 b4d1f84e
......@@ -52,6 +52,14 @@ describe('event-bus', () => {
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 () => {
await page.callMethod('clear')
await page.callMethod('on')
......
......@@ -14,6 +14,12 @@
<view>
<view v-for="(item, index) in log" :key="index">{{ item }}</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>
<!-- #ifdef APP -->
......@@ -26,6 +32,7 @@
data() {
return {
log: [] as string[],
objArg: {},
}
},
methods: {
......@@ -41,6 +48,11 @@
on2() {
uni.$on('test', this.fn2)
},
onObj() {
uni.$on('test-obj', (res: UTSJSONObject) => {
this.objArg = res
})
},
once() {
uni.$once('test', this.fn)
},
......@@ -53,6 +65,9 @@
emit() {
uni.$emit('test', 'msg:' + Date.now())
},
emitWithObj() {
uni.$emit('test-obj', { a: 1, b: 2 })
},
clear() {
this.log.length = 0
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册