javascript interoperability
This commit is contained in:
34
BlazorApp/BlazorStateApp/Pages/JSInterop.razor
Normal file
34
BlazorApp/BlazorStateApp/Pages/JSInterop.razor
Normal file
@@ -0,0 +1,34 @@
|
||||
@page "/jsinterop"
|
||||
@inject IJSRuntime _jsRuntime;
|
||||
|
||||
<h3>JSInterop</h3>
|
||||
|
||||
<div>
|
||||
<button type="button" class="btn btn-primary" @onclick="HelloWorld">
|
||||
Hello World!
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
|
||||
<div>
|
||||
<button type="button" class="btn btn-primary" @onclick="InputName">
|
||||
Input Name
|
||||
</button>
|
||||
<p>@_name</p>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
string _name;
|
||||
|
||||
private async void HelloWorld()
|
||||
{
|
||||
await _jsRuntime.InvokeVoidAsync("testFunction.helloWorld", null);
|
||||
}
|
||||
|
||||
private async void InputName()
|
||||
{
|
||||
_name = await _jsRuntime.InvokeAsync<string>("testFunction.inputName", "Send from Blazor");
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
@@ -28,5 +28,6 @@
|
||||
</div>
|
||||
|
||||
<script src="_framework/blazor.server.js"></script>
|
||||
<script src="~/test.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user