在组件UI Syntax中使用动态组件进行渲染。请问现在是否支持?或者是有没有其他类似的替代做法?
伪代码示例:
@Component
struct ComA {
build() {
Text("Hi~ 我是组件A")
}
}
@Component
struct ComB {
build() {
Text("Hi~ 我是组件B")
}
}
// 定义一个可用组件kv
const components: Record<string, object> = {
"a": ComA,
"b": ComB,
};
@Entry
@Component
struct Index {
build() {
CustomComponent({ name: "a" })
}
}
struct CustomComponent {
@Prop name: string;
build() {
components[this.name] ?? Text("无可用组件")
}
}
建议封装全局@Builder。
参考文档链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-wrapbuilder-V5