fireGlobalEvent 发送全局通知
fireGlobalEvent ^7.6
发送全局通知,通过addEventListener方法来异步接收消息
#请求参数
| Prop | Type | Required | Default | Comment |
|---|---|---|---|---|
event |
String |
Y |
- | 事件名 |
param |
Object |
Y |
- | 传送的数据 |
#入参代码示例
const params = {
event: 'xxx', //事件名 自定义
param: {
messageType: '', // stringH5用来判断消息类型,然后做相对应的处理
messageBody: {}, //传递的json对象
},
}
#接口调用示例
// 监听
this.$bridge.addEventListener('receiveMessageFromApp', (res) => {
// res.messageType:消息类型
// res.messageBody: 原生返回的json数据。
this.$bridge.showToast({
title: JSON.stringify(res),
duration: 5,
})
})
const params = {
event: 'receiveMessageFromApp', //事件名,
param: {
messageType: 'test', // stringH5用来判断消息类型,然后做相对应的处理
messageBody: {
test: 'woshishui',
}, //传递的json对象
},
}
// 触发
this.$bridge
.fireGlobalEvent(params)
.then(res => {
this.result = res;
})
#返回参数
- 成功时返回N/A
#返回示例
{
"code":0,
"msg": 'xxx'
}
浙公网安备 33010602011771号