javascript interoperability

This commit is contained in:
2023-08-25 09:32:32 +09:00
parent 95477e9b40
commit 95777f6143
4 changed files with 54 additions and 0 deletions

View 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();
}
}

View File

@@ -28,5 +28,6 @@
</div>
<script src="_framework/blazor.server.js"></script>
<script src="~/test.js"></script>
</body>
</html>