728x90
728x170

ComponentBase 상속받은 클래스를 정의합니다.

TestComponent.cs

using Microsoft.AspNetCore.Components;

namespace Blazor.AppTest.Components
{
    public class TestComponent : ComponentBase
    {
        public string? ButtonText;
        public int Value = 0;
        protected override Task OnInitializedAsync()
        {
            ButtonText = "Increment";

            return base.OnInitializedAsync();
        }

        public void IncrementCount()
        {
            this.Value += 1;

            StateHasChanged();
        }
    }
}

razor 페이지에서 위 정의한 클래스를 @inherits 을 이용해 TestComponent 를 상속받게합니다.

@page "/componenttest"
@using Blazor.AppTest.Components

@inherits TestComponent

<h3>Component Test</h3>

<button class="btn btn-primary" @onclick="IncrementCount">@ButtonText (@Value)</button>

결과

[Source]
https://github.com/kei-soft/Blazor.AppTest/tree/master/Blazor.MSDocTest

 

GitHub - kei-soft/Blazor.AppTest

Contribute to kei-soft/Blazor.AppTest development by creating an account on GitHub.

github.com

 

728x90
그리드형
Posted by kjun.kr
,