(相关资料图)
[Inject, NotNull] IJSRuntime? JS { get; set; }
await JS.InvokeVoidAsync("eval", @"let discard= open(https://www.blazor.zone/tables/edit
, _blank
)");
await JS.InvokeVoidAsync("eval", $"let discard= open({url}
, _blank
)");
var innerWidth = await JS.InvokeAsync
原文链接: https://www.frankslowcodeblog.com/post/2023/03/23/session-variable-as-cookie-in-radzen-blazor
using Microsoft.JSInterop;namespace MyProject.Utils{ public interface ICookie { public Task SetValue(string key, string value, int? days = null); public Task GetValue(string key, string def = ""); } public class CookieService: ICookie { readonly IJSRuntime JSRuntime; string expires = ""; public Cookie(IJSRuntime jsRuntime) { JSRuntime = jsRuntime; ExpireDays = 300; } public async Task SetValue(string key, string value, int? days = null) { var curExp = (days != null) ? (days > 0 ? DateToUTC(days.Value) : "") : expires; await SetCookie($"{key}={value}; expires={curExp}; path=/"); } public async Task GetValue(string key, string def = "") { var cValue = await GetCookie(); if (string.IsNullOrEmpty(cValue)) return def; var vals = cValue.Split(";"); foreach (var val in vals) if(!string.IsNullOrEmpty(val) && val.IndexOf("=") > 0) if(val.Substring(0, val.IndexOf("=")).Trim().Equals(key, StringComparison.OrdinalIgnoreCase)) return val.Substring(val.IndexOf("=") + 1); return def; } private async Task SetCookie(string value) { await JSRuntime.InvokeVoidAsync("eval", $"document.cookie = \"{value}\""); } private async Task GetCookie() { return await JSRuntime.InvokeAsync("eval", $"document.cookie"); } public int ExpireDays { set => expires = DateToUTC(value); } private static string DateToUTC(int days) => DateTime.Now.AddDays(days).ToUniversalTime().ToString("R"); }}
services.AddScoped();
[Inject, NotNull] protected ICookie? Cookie { get; set; }await Cookie.SetValue("mytest20", "Hello Blazor!");_message = await Cookie.GetValue("mytest20");
标签:
1 在新窗口打开链接[Inject,NotNull]IJSRuntime?JS{get;set;}awaitJ
食材:猪肺500g,霸王花干20g,茶树菇30g,无花果干3颗,大枣2颗,生姜
生殖道病毒感染,关于生殖道病毒感染介绍这个很多人还不知道,我们一起
1、注意休息,避免疲劳,保证充足的睡眠,保持愉快的心情,避免面部表
今天来聊聊021感动中国人物颁奖词,2021感动中国人物的文章,现在就为