# fireGlobalEvent ^7.6
发送全局通知,通过 addEventListener 方法来异步接收消息
# 请求参数
| Prop | Type | Required | Default | Comment | 
|---|---|---|---|---|
| event | String | Y | - | 事件名 | 
| param | Object | Y | - | 传送的数据 | 
# 入参代码示例
let params = {
  event: "xxx", //事件名 自定义
  param: {
    messageType: "", // stringH5用来判断消息类型,然后做相对应的处理
    messageBody: {}, //传递的json对象
  },
};
1
2
3
4
5
6
7
2
3
4
5
6
7
# 接口调用示例
// 监听
this.$bridge.addEventListener("receiveMessageFromApp", (res) => {
  // res.messageType:消息类型
  // res.messageBody: 原生返回的json数据。
  this.$bridge.showToast({
    title: JSON.stringify(res),
    duration: 5,
  });
});
let params = {
  event: "receiveMessageFromApp", //事件名,
  param: {
    messageType: "test", // stringH5用来判断消息类型,然后做相对应的处理
    messageBody: {
      test: "woshishui",
    }, //传递的json对象
  },
};
// 触发
this.$bridge.fireGlobalEvent(params).then((res) => {
  this.result = res;
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 返回参数
- 成功时返回 N/A
# 返回示例
{
  "code":0,
  "msg": 'xxx'
}
1
2
3
4
2
3
4
