3 回答

TA貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個(gè)贊
只需將 index.html 代碼復(fù)制到服務(wù)器項(xiàng)目中的 .cshtml(在以下示例中名為 BlazorApp.cshtml)中,然后回退到此頁面。
public void Configure(IApplicationBuilder app)
{
...
app.UseEndpoints(endpoints =>
{
...
endpoints.MapFallbackToPage("/BlazorApp");
}
}
并使用標(biāo)簽更新代碼以<environment>方便您。

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超2個(gè)贊
我想在開發(fā)期間添加 Tailwind CDN 腳本標(biāo)簽。我最終使用了以下解決方案:
索引.html
<script src="_framework/blazor.webassembly.js"></script>
<script>
// If localhost, add tailwind CDN (or any other script that you want)
if (window.location.hostname == 'localhost') {
var customScript = document.createElement('script');
customScript.setAttribute('src', 'https://cdn.tailwindcss.com');
document.head.appendChild(customScript);
}
</script>

TA貢獻(xiàn)1785條經(jīng)驗(yàn) 獲得超8個(gè)贊
請(qǐng)檢查此答案中的解決方案(與上面鏈接的問題相同),這似乎有效。
基本上,解決方法是在Head.razor根據(jù)解決方案調(diào)用的新組件中使用它:
@inject IWebAssemblyHostEnvironment hostEnv
@if (hostEnv.IsDevelopment())
{
<title>BlazorWasmApp - In Debug</title>
<link href="css/debug.css" rel="stylesheet" />
}
else
{
<title>BlazorWasmApp - Not Debug</title>
<link href="css/live.css" rel="stylesheet" />
}
新Head.razor組件:
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
//Add the Head to root components
builder.RootComponents.Add<Head>("head");
builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
await builder.Build().RunAsync();
}
添加回答
舉報(bào)