In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to share with you the relevant knowledge of what the life cycle of Blazor components is. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
Execution cycle
1. SetParametersAsync
2. OnInitializedAsync (called twice) and OnInitialized
3. OnParametersSetAsync or OnParametersSet
4. OnAfterRenderAsync and OnAfterRender
5. ShouldRender is called every time the component is rendered
Parsing SetParametersAsync in each cycle
Each time SetParametersAsync is called, ParameterView contains the entire set of parameter values.
The default implementation of SetParametersAsync uses the [Parameter] or [CascadingParameter] attribute (which has a corresponding value in ParameterView) to set the value of each property. Parameters that have no corresponding values in ParameterView remain the same.
If base.SetParametersAync is not called, the custom code can interpret the passed-in parameter values in any way needed. For example, it is not required to assign incoming parameters to the properties of the class.
If an event handler is set, it will be unhooked during disposal. For more information, see the using IDisposable to dispose of components section.
Public override async Task SetParametersAsync (ParameterView parameters) {await... Await base.SetParametersAsync (parameters);} OnInitializedAsync and OnInitialized
Components in SetParametersAsync are initialized after receiving initial parameters from their parent components, at which point OnInitializedAsync and OnInitialized are called.
OnInitializedAsync is used when the component performs an asynchronous operation and should be refreshed after the operation is complete.
For synchronous operations, replace OnInitialized:
The Blazor Server application that pre-renders its content calls OnInitializedAsync twice:
Called once when the component is initially statically rendered as part of the page.
Called a second time when the browser reestablishes a connection to the server.
To prevent developer code in OnInitializedAsync from running twice, see the stateful reconnect section after pre-rendering.
When the Blazor Server application is pre-rendered, it is impossible to perform specific operations such as calling JavaScript because the connection with the browser has not been established. When pre-rendering, components may need to be rendered differently. For more information, see the section detecting when the application is pre-rendered.
If an event handler is set, it will be unhooked during disposal.
Remarks
When applying parameters and property values, asynchronous operations must occur during OnParametersSetAsync lifecycle events.
Protected override void OnInitialized () {...} protected override async Task OnInitializedAsync () {await...} OnParametersSetAsync or OnParametersSet
Called under the following circumstances:
After initializing a component in OnInitializedAsync or OnInitialized.
When the parent component is re-rendered and provides the following
The only known primitive immutable type that at least one parameter has changed.
Parameters of any complex type. The framework has no way of knowing whether the value of a complex type parameter has changed internally, so it treats the parameter set as changed.
Remarks
When applying parameters and property values, asynchronous operations must occur during OnParametersSetAsync lifecycle events.
Protected override async Task OnParametersSetAsync () {await...} protected override void OnParametersSet () {...} above is all the content of the article "what is the life cycle of Blazor components?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.