[英]what is the right way to render blazor component?
我不明白渲染 Blazor 組件的正確方法是什么。
我已經在 C# ASP NET Core web 應用程序中安裝了 razor 服務器。 我正在嘗試使用render-mode="ServerPrerendered"或render-mode="Server"渲染組件
在這兩種情況下,我都需要聲明腳本_framework/blazor.server.js
如果我在所有其他腳本所在的主_Layout.cshtml上或在 body 標記的末尾聲明腳本,則組件已死:事件和函數不起作用,無法動態更改組件; 我可以在控制台上看到 web 應用程序啟動后立即建立連接。 因此,當我導航到擁有組件的頁面時,為時已晚。
相反,如果我在組件之后聲明腳本,則一切正常。 組件渲染良好,事件和函數工作正常。
所以現在我使用2。但是這樣,每次我需要在新頁面上使用一個組件時,我都會一次又一次地聲明腳本,因此每次都會破壞並建立連接。
我認為這不是干凈的解決方案。 那么,渲染組件的正確方法是什么?
提前謝謝你,抱歉英語不好
從 Visual Studio 最新版本提供的“BlazorApp”模板來看,你把它放在Pages/_Hosts.cshtml
的末尾:
<body>
<component type="typeof(App)" render-mode="ServerPrerendered" />
<div id="blazor-error-ui">
<environment include="Staging,Production">
An error has occurred. This application may no longer respond until reloaded.
</environment>
<environment include="Development">
An unhandled exception has occurred. See browser dev tools for details.
</environment>
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>
<script src="_framework/blazor.server.js"></script>
</body>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.