`title: Service Worker 客户端广播与状态总线(clients.postMessage)``categories: Web 开发/前端/数据管理``keywords: Service Worker,clients.postMessage,广播,总线,状态``description: 使用 clients.postMessage 在 SW 与页面间广播状态更新,构建轻量状态总线,统一数据处理与提示。`广播示例self.addEventListener('message', async (e) => { const clientsList = await self.clients.matchAll({ type: 'window' }); for (const client of clientsList) client.postMessage({ type: 'state', payload: e.data }); });

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部
1.775431s