且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

blazor作用域服务初始化两次

更新时间:2023-10-11 22:48:04

在使用预渲染时,它被调用了两次.转到_Host.cshtml并将render-mode="ServerPrerendered"更改为render-mode="Server",它将仅被调用一次:

It is called twice, as you are using pre-rendering. Go to _Host.cshtml and change render-mode="ServerPrerendered" to render-mode="Server", and it would be called only once:

<app>
    <component type="typeof(App)" render-mode="Server" />
</app>

参考:

https://docs.microsoft.com/zh-cn/aspnet/core/blazor/lifecycle?view=aspnetcore-3.1#stateful-reconnection-after-prerendering