Blazor-如何动态创建组件 [英] Blazor - How to create Components dynamically

查看:473
本文介绍了Blazor-如何动态创建组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想测试是否可以动态创建Blazor组件.

I want to test if it was possible to create Blazor components dynamically.

我找不到任何方法可以做到这一点.我对此链接上找到的一些动态内容进行了一些实验,但并未结束任何结果.

I can't find any way to do this. I have experimented a bit with some dynamic content found on this link but have not ended up with any results.

推荐答案

对于0.2版,这是史蒂夫·桑德森的答案:

For version 0.2 this is the answer from Steve Sanderson:

我们将来将实现更好的API来构建RenderFragments,但是 现在你可以

We'll implement nicer APIs to build RenderFragments in the future, but for now you can

@CreateDynamicComponent();
@functions {
    RenderFragment CreateDynamicComponent() => builder =>
    {
        builder.OpenComponent(0, typeof(SurveyPrompt));
        builder.AddAttribute(1, "Title", "Some title");
        builder.CloseComponent();
    };
}

这些都是非常低级的API(甚至没有记录),因此我们希望不要 许多人现在需要这样做.为此将使用更高级别的API 以后再来.

Those are very low-level APIs (not even documented) so we hope not many people need to do this right now. Higher-level APIs for this will come later.

此处找到

这篇关于Blazor-如何动态创建组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆