Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Blazor Interop LocalStorage 0.4.0更改为0.5.1_Javascript_C#_Blazor - Fatal编程技术网

Javascript Blazor Interop LocalStorage 0.4.0更改为0.5.1

Javascript Blazor Interop LocalStorage 0.4.0更改为0.5.1,javascript,c#,blazor,Javascript,C#,Blazor,我正在学习如何使用Blazor Interop,但最近它发生了变化,因此我没有任何简单的示例可以学习。我从一个工作示例复制了一段代码,并希望将其更改为新的Interop。下面是Blazor 0.4.0 from.js文件中的代码 Blazor.registerFunction('saveToken', token => { window.localStorage.setItem('jwt', token); console.log("Authentication token has bee

我正在学习如何使用Blazor Interop,但最近它发生了变化,因此我没有任何简单的示例可以学习。我从一个工作示例复制了一段代码,并希望将其更改为新的Interop。下面是Blazor 0.4.0 from.js文件中的代码

Blazor.registerFunction('saveToken', token => {
window.localStorage.setItem('jwt', token);
console.log("Authentication token has been stored.");
return true;
}))

这是来自Blazor页面的.csthml函数

            RegisteredFunction.Invoke<bool>("saveToken", token);
RegisteredFunction.Invoke(“saveToken”,令牌);

我已经阅读了Blazor Doc Interop,这个示例很容易理解,但是对于localstorage,我不知道如何在0.5+中使函数通过
窗口可见

window.saveToken = token => {
    window.localStorage.setItem('jwt', token);
    console.log("Authentication token has been stored.");
    return true;
};

JsRuntime.Current.InvokeAsync<bool>("saveToken", token);
window.saveToken=token=>{
window.localStorage.setItem('jwt',标记);
log(“已存储身份验证令牌”);
返回true;
};
JsRuntime.Current.InvokeAsync(“saveToken”,token);

或者,您可以使用已经为您执行互操作的Nuget软件包,例如: