728x90
    
    
  결과

1. wwwroot > css > app.css에 spinner style 추가
.spinner {
    border: 16px solid silver;
    border-top: 16px solid #337AB7;
    border-radius: 50%;
    width: 80px;
    height: 80px;
    animation: spin 700ms linear infinite;
    top: 40%;
    left: 55%;
    position: absolute;
}
@keyframes spin {
    0% {
        transform: rotate(0deg)
    }
    100% {
        transform: rotate(360deg)
    }
}
2. FetchData.razor 에 spinner 적용 및 데이터 비동기 처리
@page "/fetchdata"
<PageTitle>Weather forecast</PageTitle>
@using Blazor.AppTest.Data
@inject WeatherForecastService ForecastService
<h1>Weather forecast</h1>
<p>This component demonstrates fetching data from a service.</p>
<h5>Search Summary</h5>
<Search OnSearchChanged="SearchData" />
@if (forecasts == null)
{
    <p><em>Loading...</em></p>
    <div class="spinner"></div>
}
else
{
    <table class="table">
        <thead>
            <tr>
                <th>Date</th>
                <th>Temp. (C)</th>
                <th>Temp. (F)</th>
                <th>Summary</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var forecast in forecasts)
            {
                <tr>
                    <td>@forecast.Date.ToShortDateString()</td>
                    <td>@forecast.TemperatureC</td>
                    <td>@forecast.TemperatureF</td>
                    <td>@forecast.Summary</td>
                </tr>
            }
        </tbody>
    </table>
}
@code {
    private WeatherForecast[]? originForecasts;
    private WeatherForecast[]? forecasts;
    protected override async Task OnInitializedAsync()
    {
        // 데이터 비동기 처리
        await Task.Run(LoadData);
    }
    private async void LoadData()
    {
        // Test Sleep
        System.Threading.Thread.Sleep(2000);
        originForecasts = await ForecastService.GetForecastAsync(DateTime.Now);
        forecasts = originForecasts.ToArray();
    }
    private void SearchData(string searchText)
    {
        forecasts = originForecasts?.Where(c => c.Summary.ToUpper().Contains(searchText.ToUpper())).ToArray();
    }
}
[Source Code]
https://github.com/kei-soft/Blazor.AppTest
GitHub - kei-soft/Blazor.AppTest
Contribute to kei-soft/Blazor.AppTest development by creating an account on GitHub.
github.com
728x90
    
    
  'C# > Blazor' 카테고리의 다른 글
| [Blazor] ShouldRender - 불필요한 렌더링 방지 (0) | 2022.12.19 | 
|---|---|
| [Blazor] IDisposable 처리하기 (0) | 2022.12.19 | 
| [Blazor] MVVM Pattern 사용하기 (0) | 2022.10.26 | 
| [Blazor] Prism 사용하기 - EventAggregator (0) | 2022.10.24 | 
| [Blazor] Service 사용하여 데이터 바인딩 시키기 (종속성주입) (0) | 2022.10.21 |