You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.8 KiB

@page "/weather"
11 months ago
@using MyBlazorApp.Services
@inject WeatherForecastService ForecastService
@rendermode InteractiveServer
11 months ago
<h3>Weather Forecast ☀</h3>
11 months ago
@if (isLoading)
{
11 months ago
<p><em>불러오는 중...</em></p>
}
11 months ago
else if (forecasts is not null && forecasts.Any())
{
11 months ago
<div>
<label class="text-info">앞으로 @(forecasts.Count())일에 대한 일기예보</label>
</div>
<table class="table">
<thead>
<tr>
11 months ago
<th>날짜</th>
<th>온도 (C)</th>
<th>온도 (F)</th>
<th>요약</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>
}
11 months ago
else
{
<p>유효한 데이터가 없습니다.</p>
}
@code {
11 months ago
private IEnumerable<WeatherForecast> forecasts;
private bool isLoading = true;
protected override void OnInitialized()
{
LoadForecasts();
}
11 months ago
private async Task LoadForecasts()
{
11 months ago
try
{
Console.WriteLine("Call Forecasts");
forecasts = await ForecastService.GetForecastsAsync();
Console.WriteLine($"Received {forecasts.Count()} reulsts");
}
catch (Exception ex)
{
Console.WriteLine($"Error fetching data: {ex.Message}");
}
finally
{
isLoading = false;
Console.WriteLine("Call StateHasChanged");
StateHasChanged();
Console.WriteLine("End StateHasChanged");
}
}
11 months ago
}