我的前端有一个 EventSource 监听器,调用一个复杂的后端方案。此代码块是用 Typescript 编写的。
import * as EventSource from 'eventsource';
private streamData() {
let source = new EventSource('http://localhost:3000/websocket/server/stream');
source.onopen = (e) => {
};
source.onmessage = (e) => {
console.log('id: ' + (<any>e).lastEventId + '; type: ' + e.type + ' data: ' + e.data);
};
}
我将以下响应发送回我的服务器:
res.write('id: ' + this.messageId++ + '\n');
res.write('type: message\n');
res.write('data: ' + message + '\n\n');
res.flush();
<小时/>
但是,在 xhr 监视器上,我看不到 EventStream 数据。
我在前端获取信息,所以这对我来说不是一个阻塞问题,但可能会在稍后的调试中带来一些问题。
最佳答案
我也遇到了同样的问题。仅当您使用 EventSource 类的内置浏览器实现时,当您使用 eventsource polyfill 时,数据才不会显示。
关于javascript - 事件流数据未显示在 Chrome 控制台中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55201372/