Cnfzh 软件博客

Blazor 组件通信的四种姿势

参数、级联、事件回调与状态容器,各用在什么场合。

参数向下,事件向上

父子通信用 [Parameter] 加 EventCallback,这是主干道。

级联参数

跨层传递主题、登录态这类全局信息,一级一级传参会爆炸。

状态容器

需要跨页面共享时,用一个 Scoped 服务当状态容器,比级联值更可控。

别过度设计

能用参数解决的不要上状态容器——调试时多一跳都是成本。

Comments 0

No comments yet. Say something!

Email verification is required; the code is valid for 10 minutes.

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.