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

微前端设计与实现

by Luca Mezzalira
August 2022
Beginner to intermediate
270 pages
7h 38m
Chinese
Posts & Telecom Press
Content preview from 微前端设计与实现
微前端技术实现
115
的可见性,但收银台域逻辑会泄露到
App shell
程序中,这可能会对代码库造成污染。此
外,如果采用这种方案,每次要更改可见性逻辑时,我们都需要发布一个新的
App shell
本。由于收银台体验和
App shell
由不同的开发团队负责,创建这样的依赖项只会带来更多
的麻烦,而非好处。
更好的解决方案是让负责
App shell
团队添加组件,组件本身会根据一组条件(比如页
URL
)来控制显示和隐藏。这样,任何逻辑变更或改进都将发生在组件内部,而不会将
这些实现细节泄露到
App shell
。如果负责
App shell
的团队在编译期集成功能,则只需
要升级用于加载组件的库即可。但在
Module Federation
支持下,团队则不需要做任何事
情,因为新组件将在运行时加载。
要显示购物车中的商品总数,我们首先需要通过后端提供的
API
将商品添加到购物车中
然后通知购物车组件更新界面中显示的值。实现这个效果的最佳方法是通过事件触发器实
例触发一个事件。当购物车组件接收到事件时,它将使用一个
API
来获取当前购物车中的
商品数量(如第
4
章所述)
最后,当用户通过单击购物车组件开始结账时,我们所要做的就是更改
URL
,通知
App
shell
跳转到收银台微前端。
从长远来看,预先投入一些时间来考虑实现像购物车组件这样的简单元素是事半功倍的。
尽管位于不同的域(
App shell
)中
,但购物车组件仍然保持高度的封装性。它将通过事件
触发器接收来自系统其他部分触发的事件,并将用户路由到收银台页面。遵循微前端原则 ...
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