【发布时间】:2020-06-22 00:35:13
【问题描述】:
是否可以在.razor 文件中呈现<component> 标签。我有一个需要在另一个 Blazor 组件中呈现静态脚本的要求。因此,我使用BuildRenderTree 概念创建了脚本标签,并尝试将<component> 标签与render-mode 添加为Static。但是,它不会在网页中呈现。
ScriptRender.razor
public class ScriptRender : ComponentBase
{
[Parameter]
public List<string> Source { get; set; }
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
foreach (var scriptPath in Source)
{
builder.OpenElement(0, "script");
builder.AddAttribute(1, "src", scriptPath);
builder.CloseElement();
}
}
}
BlazorComponent.razor
<component type="typeof(ScriptRender)" render-mode="Static"></component>
// Rest of component rendering logics
我知道,<component> 标签可以在 layout.cshtml 页面中使用。不在 Blazor 剃须刀页面中工作?
【问题讨论】:
-
此资源可能对您有所帮助! github.com/dotnet/aspnetcore/issues/16218
标签: blazor blazor-server-side blazor-client-side