惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
S
Securelist
P
Proofpoint News Feed
D
DataBreaches.Net
Cisco Talos Blog
Cisco Talos Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Project Zero
Project Zero
A
About on SuperTechFans
罗磊的独立博客
WordPress大学
WordPress大学
月光博客
月光博客
Latest news
Latest news
C
Cyber Attacks, Cyber Crime and Cyber Security
GbyAI
GbyAI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - 三生石上(FineUI控件)
F
Fortinet All Blogs
W
WeLiveSecurity
Attack and Defense Labs
Attack and Defense Labs
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Privacy International News Feed
AI
AI
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Stack Overflow Blog
Stack Overflow Blog
M
MIT News - Artificial intelligence
Help Net Security
Help Net Security
T
Tor Project blog
V
Vulnerabilities – Threatpost
C
Cisco Blogs
I
Intezer
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
MyScale Blog
MyScale Blog
雷峰网
雷峰网
MongoDB | Blog
MongoDB | Blog
Forbes - Security
Forbes - Security
V
V2EX
Apple Machine Learning Research
Apple Machine Learning Research
T
Threat Research - Cisco Blogs
B
Blog RSS Feed
博客园 - 叶小钗
N
News and Events Feed by Topic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Simon Willison's Weblog
Simon Willison's Weblog
C
CERT Recently Published Vulnerability Notes
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic

WishMeLz - Vue

Electron 主进程起一个可用的 HTTPS 静态服务器 - WishMeLz van-nav-bar 页面宽度改动 placeholder占位元素未自动更新 - WishMeLz Vant UI van-search 键盘没有显示「搜索」按钮的解决方案 - WishMeLz Lodop、C-Lodop使用笔记 - WishMeLz el-upload beforeUpload 使用async无法拦截 ANSI 字体在前端展示 Jenkins日志 - WishMeLz 获取视频某一秒的截图 - WishMeLz elementui 动态生成的 el-form-item rules校验失效 vue中v-html - WishMeLz
SSE(Server-Sent Events) - WishMeLz
WishMeLz · 2026-06-01 · via WishMeLz - Vue

服务端

const express = require("express");
const cors = require("cors");

const app = express();
const port = 6548;

app.use(cors());

app.get("/sse", (req, res) => {
  res.set({
    "Content-Type": "text/event-stream",
    "Cache-Control": "no-cache",
    Connection: "keep-alive",
  });

  res.flushHeaders();

  setInterval(() => {
    const data = {
      message: `Server time is ${new Date().toLocaleTimeString()}`,
    };

    res.write(`data: ${JSON.stringify(data)}\n\n`);
  }, 1000);
});

app.listen(port, () => {
  console.log(`Server started on port ${port}`);
});

前端

 const events = document.getElementById("events");
      const source = new EventSource("http://127.0.0.1:6548/sse");
      source.onmessage = (event) => {
        const data = JSON.parse(event.data);
        const message = data.message;
        console.log(event);
     
      };

最后编辑时间为: June 25th , 2024 at 07:04 pm
本文由 Wish 创作,采用 知识共享署名 4.0 国际许可协议进行许可
可自由转载、引用,但需署名作者且注明文章出处

标签 : 无标签