在 Blazor 项目中,JavaScript 函数区分
编辑: 显然,
null
和 undefined
。当从 C# 中传递 null
(await jsRuntime.InvokeAsync<long>("func", null, "str")
) 时,JS 侧接收到的值为 null
(typeof arg1 === 'object'
)。如何从 C# 侧传递参数以接收 undefined
(typeof arg1 === 'undefined'
)?编辑: 显然,
null
的行为不一致,这取决于参数的位置。
JS: func1: function (arg1) {
console.log("func1", typeof arg1);
},
func2: function (arg1, arg2) {
console.log("func2", typeof arg1);
},
C#:
await jsRuntime.InvokeVoidAsync("utils.func1", null);
await jsRuntime.InvokeVoidAsync("utils.func1");
await jsRuntime.InvokeVoidAsync("utils.func1", "aaa");
await jsRuntime.InvokeVoidAsync("utils.func2", null, 123);
await jsRuntime.InvokeVoidAsync("utils.func2", "aaa", 123);
输出:
func1 undefined
func1 undefined
func1 string
func2 object
func2 string
await jsRuntime.InvokeAsync<long>("func")
吗? - Eliseo