Blazor-全局对象-使用SessionStorage? [英] Blazor - Global Objects - Use SessionStorage?
问题描述
我有一个Blazor应用,包含多个页面和组件等.我需要坚持&在页面和组件之间传递全局对象.例如,假设将在页面之间读取和更新CUSTOMER对象.做这个的最好方式是什么?使用SessionStorage?
I have a Blazor app, with mulitple pages and components etc. I need to persist & pass a global object between pages and components. Say for example, a CUSTOMER object that will be read and updated between pages. What is the best way to do this? Use SessionStorage?
https://docs.microsoft.com/en-us/aspnet/core/blazor/state-management?view=aspnetcore-3.1
还是使用这样的服务?StateManager?
Or use a Service like this? StateManager?
https://blog.jeremylikness.com/blog/blazor-state-management/
有什么想法吗?提前谢谢
Thoughts? Thx in advance
推荐答案
要链接的第一篇文章是使用服务器端模型构建Blazor应用程序时的操作.如果您使用的是Blazor客户端(WebAssembly,WASM)模型,那么它不会给您任何用处.
The first article you link to is what you would do if you're building a Blazor app with the server-side model. It doesn't give you anything of use if you're using a Blazor client-side (WebAssembly, WASM) model.
您链接到的第二篇文章比较了Blazor Server和Blazor WASM之间的方法.
The second article you link to contrasts approaches between Blazor Server and Blazor WASM.
因此,如果您使用的是Blazor WebAssembly,则应使用Jeremy Likeness'StateManager之类的服务(除非您想自己编写一个代码!),但是如果使用的是Blazor Server-side,则不需要,您可以只使用发布的Microsoft文章中的建议.
So, if you're using Blazor WebAssembly, you should us a service like Jeremy Likeness' StateManager (unless you want to code one yourself!), but if you are using Blazor Server-side, you don't need one, you can just use the advice in that Microsoft article you posted.
这篇关于Blazor-全局对象-使用SessionStorage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!