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"
@using MyBlazorApp.Services
@inject WeatherForecastService ForecastService
@rendermode InteractiveServer
<h3>Weather Forecast ☀</h3>
@if (isLoading)
{
<p><em>불러오는 중...</em></p>
}
else if (forecasts is not null && forecasts.Any())
{
<div>
<label class="text-info">앞으로 @(forecasts.Count())일에 대한 일기예보</label>
</div>
<table class="table">
<thead>
<tr>
<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>
}
else
{
<p>유효한 데이터가 없습니다.</p>
}
@code {
private IEnumerable<WeatherForecast> forecasts;
private bool isLoading = true;
protected override void OnInitialized()
{
LoadForecasts();
}
private async Task LoadForecasts()
{
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");
}
}
}