私はBlazor Interopの使い方を学んでいますが、最近変更されていますので、実際のコードからコピーした覚えがない簡単な例はありません。新しいInteropに変更したいのですがブレーザー0.4.0 .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);
私はすでにBlazor Doc Interop https://blazor.net/docs/javascript-interop.htmlを読んでおり、その例は非常に簡単でしたが、localstorageではどのように
0.5+では、関数をwindow
表示するだけです。
window.saveToken = token => {
window.localStorage.setItem('jwt', token);
console.log("Authentication token has been stored.");
return true;
};
JsRuntime.Current.InvokeAsync<bool>("saveToken", token);
または、あなたはこのようなあなたのためのinteropを既に行っているNugetパッケージを使うことができます: https : //github.com/BlazorExtensions/Storage