Код: Выделить всё
library-input.jsКод: Выделить всё
#updateValue(value) {
// ... updating the native `value` attribute
const valueEvent = new CustomEvent("valueChange", {
detail: this.#value,
bubbles: true,
});
this.dispatchEvent(valueEvent);
}
< /code>
libraryInput.razorКод: Выделить всё
@inject IJSRuntime JSRuntime
@namespace BlazorWrapperForLibrary
@using System.Text.Json
@code {
private ElementReference libInput;
private const string JAVASCRIPT_FILE = "/js/library-components.js";
private const string INTEROP_FILE = "/js/lib-input.interop.js";
private IJSObjectReference? Module { get; set; }
private IJSObjectReference? Interop { get; set; }
[Parameter]
public string? Value { get; set; }
[Parameter]
public EventCallback ValueChanged {get; set;}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
Module = await JSRuntime.InvokeAsync("import", JAVASCRIPT_FILE);
Interop = await JSRuntime.InvokeAsync("import", INTEROP_FILE);
}
}
}
< /code>
CustomEvents.csКод: Выделить всё
public class InputValueChangeEventArgs : EventArgs
{
public string? detail { get; set; }
}
[EventHandler("onvalueChange", typeof(InputValueChangeEventArgs), enableStopPropagation: true, enablePreventDefault: true)]
public static class EventHandlers
{
}
< /code>
Counter.razorКод: Выделить всё
@page "/counter"
@code {
private string newValue = "undefined";
private void InputChanged(InputValueChangeEventArgs value)
{
Console.WriteLine(value.detail);
}
}
Код: Выделить всё
onGlobalEvent(e)Подробнее здесь: https://stackoverflow.com/questions/782 ... -component