Added web assembly
This commit is contained in:
45
WebAssembly/Pages/Counter.razor
Normal file
45
WebAssembly/Pages/Counter.razor
Normal file
@ -0,0 +1,45 @@
|
||||
@page "/counter"
|
||||
@using System.Diagnostics
|
||||
|
||||
<PageTitle>Counter</PageTitle>
|
||||
|
||||
<h1>Counter</h1>
|
||||
|
||||
<p role="status">Current count: @_currentCount</p>
|
||||
<p role="status">Runtime: @_stopwatch.Elapsed.ToString("g")</p>
|
||||
|
||||
|
||||
<button class="btn btn-success" @onclick="Start">Start</button>
|
||||
<button class="btn btn-danger" @onclick="Stop">Stop</button>
|
||||
<button class="btn btn-secondary" @onclick="Reset">Reset</button>
|
||||
|
||||
@code {
|
||||
private int _currentCount = 0;
|
||||
private bool _cancel;
|
||||
private readonly Stopwatch _stopwatch = new();
|
||||
|
||||
private async Task Start()
|
||||
{
|
||||
_stopwatch.Start();
|
||||
_cancel = false;
|
||||
while (!_cancel)
|
||||
{
|
||||
_currentCount++;
|
||||
StateHasChanged();
|
||||
await Task.Delay(10);
|
||||
}
|
||||
_stopwatch.Stop();
|
||||
}
|
||||
|
||||
private void Stop()
|
||||
{
|
||||
_cancel = true;
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
_cancel = true;
|
||||
_currentCount = 0;
|
||||
_stopwatch.Reset();
|
||||
}
|
||||
}
|
57
WebAssembly/Pages/FetchData.razor
Normal file
57
WebAssembly/Pages/FetchData.razor
Normal file
@ -0,0 +1,57 @@
|
||||
@page "/fetchdata"
|
||||
@inject HttpClient Http
|
||||
|
||||
<PageTitle>Weather forecast</PageTitle>
|
||||
|
||||
<h1>Weather forecast</h1>
|
||||
|
||||
<p>This component demonstrates fetching data from the server.</p>
|
||||
|
||||
@if (forecasts == null)
|
||||
{
|
||||
<p><em>Loading...</em></p>
|
||||
}
|
||||
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[]? forecasts;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
|
||||
}
|
||||
|
||||
public class WeatherForecast
|
||||
{
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public string? Summary { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
}
|
||||
}
|
9
WebAssembly/Pages/Index.razor
Normal file
9
WebAssembly/Pages/Index.razor
Normal file
@ -0,0 +1,9 @@
|
||||
@page "/"
|
||||
|
||||
<PageTitle>Index</PageTitle>
|
||||
|
||||
<h1>Hello, world!</h1>
|
||||
|
||||
Welcome to your new app.
|
||||
|
||||
<SurveyPrompt Title="How is Blazor working for you?" />
|
Reference in New Issue
Block a user