Skip to Content
微前端设计与实现
book

微前端设计与实现

by Luca Mezzalira
August 2022
Beginner to intermediate
270 pages
7h 38m
Chinese
Posts & Telecom Press
Content preview from 微前端设计与实现
26
3
这两种情况都不会有任何扩展性问题。如果你的团队有更强的前端技能,强烈建议使用客
户端路由,这样基于后端配置使用客户端路由就自然而然了。
这些路由方法都不是互斥的。正如你将在本书后面看到的那样,可以把
CDN
和源服务器
(或者客户端和
CDN
)结合起来使用
。重要的是我们希望如何在应用中使用路由,这一决
定将影响我们如何开发微前端应用。
3.1.6
 微前端通信
在理想情况下,所有的微前端都是自给自足的,因此微前端不需要相互通信。但现实不尽
如人意,因为有时候需要把用户的交互信息通知给其他微前端,尤其是当我们在同一个页
面上使用多个微前端时。
在同一个页面上有多个微前端时,要为用户提供一致、连贯的用户界面会很复杂。同样,
在不同团队负责的微前端之间进行通信也很复杂。请记住,每个微前端都不应该知晓同一
页面上的其他微前端,否则,我们就违反了独立部署的原则。
在这种情况下,有几种技术选型可以通知其他微前端有事件发生。我们可以在每个微前端
中注入
事件总线
eventbus
,这种机制通过在总线上发送事件让解耦的组件之间能够相互
通信,一个微前端发送的事件会通知到每个微前端。如果某个微前端对所发送的事件感兴
趣,那么它可以监听事件的触发并做出反应和处理,如图
3-5
所示。
事件触发器、PubSub
或自定义事件
组件A或者
iframe
组件B或者
iframe
组件C或者
iframe
3-5:事件触发器和自定义事件
微前端的架构和挑战
27
为了将事件总线注入到微前端中,我们需要微前端容器来实例化事件总线,并将其注入到 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Python语言及其应用(第2版)

Python语言及其应用(第2版)

Bill Lubanovic

Publisher Resources

ISBN: 9787115595089