ASP.NET Core Razor Component life cycle
Blazor 元件在啟動時會有一連串的事件觸發,然而在元件觸發時會因不同狀況下所觸發的事件有所不同,下列Code可放在Blazor @Code中來做事件的執行順序觀察。
/// <summary>
/// 當參數 (設定時 SetParametersAsync)
/// </summary>
/// <param name="parameters"></param>
/// <returns></returns>
public override async Task SetParametersAsync(ParameterView parameters)
{
Console.WriteLine("Trigger SetParametersAsync");
await base.SetParametersAsync(parameters);
}
/// <summary>
/// 元件初始化
/// </summary>
protected override void OnInitialized()
{
Console.WriteLine("Trigger OnInitialized");
base.OnInitialized();
}
/// <summary>
/// 元件初始化
/// </summary>
protected override async Task OnInitializedAsync()
{
Console.WriteLine("Trigger OnInitializedAsync");
await base.OnInitializedAsync();
}
/// <summary>
/// 設定參數之後
/// </summary>
protected override void OnParametersSet()
{
Console.WriteLine("Trigger OnParametersSet");
base.OnParametersSet();
}
/// <summary>
/// 設定參數之後
/// </summary>
/// <returns></returns>
protected override async Task OnParametersSetAsync()
{
Console.WriteLine("Trigger OnParametersSetAsync");
await base.OnParametersSetAsync();
}
/// <summary>
/// 元件轉譯
/// </summary>
/// <param name="firstRender"></param>
protected override void OnAfterRender(bool firstRender)
{
Console.WriteLine("Trigger OnAfterRender(firstRender={0})", firstRender);
base.OnAfterRender(firstRender);
}
/// <summary>
/// 元件轉譯
/// </summary>
/// <param name="firstRender"></param>
/// <returns></returns>
protected override async Task OnAfterRenderAsync(bool firstRender)
{
Console.WriteLine("Trigger OnAfterRenderAsync(firstRender={0})", firstRender);
await base.OnAfterRenderAsync(firstRender);
}
/// <summary>
/// 隱藏 UI 重新整理
/// </summary>
/// <returns></returns>
protected override bool ShouldRender()
{
Console.WriteLine("Trigger ShouldRender");
return base.ShouldRender();
}
留言
張貼留言