带有参数的 c# WASM Uikit 通知

c# WASM Uikit notification with parameters

我在调用 uikit 通知并设置位置和超时时遇到问题

uikit 原创:

#1 UIkit.notification('My message');
#2 UIkit.notification('My message', status);
#3 UIkit.notification('My message', { /* options */ });
#4 UIkit.notification({ /* options */ });

这有效,但没有位置或超时

_IJSRuntime.InvokeVoidAsync("UIkit.notification", new[] { label, color});

代码:

private IJSRuntime _IJSRuntime { get; set; }
public UIKit(IJSRuntime iJSRuntime)
{
  _IJSRuntime = iJSRuntime;
}


public void Notification(string label, string color, string position = "bottom-right")
{
    _IJSRuntime.InvokeVoidAsync("UIkit.notification", "{" + $"message:'{label}', status:'{color}', timeout:5000, pos:'{position}'" + "}" );
}

有人能帮帮我吗?

不是我最喜欢的,但我的解决方案是:

新建一个js文件“UiKitCustom.js”

function Notification(label, color, timeout, position) {
UIkit.notification({
    message: label,
    status: color,
    timeout: timeout,
    pos: position
});
}

并调用这个函数

await _IJSRuntime.InvokeVoidAsync("Notification", new[] { $"{label}", $"{color}", $"{timeoute}", $"{position}" });

但我希望有人能给我一个更好的方法:)