希望在自定义UI组件的构造函数中做一些工作。下面代码中的自定义的构造方法未被调用。代码如下:
// BusinessDialog.ets
@CustomDialog
export struct BusinessDialog {
@State originUrlString: string = ''
controllerDialog: CustomDialogController
@State private businessParams?: BusinessParams = new BusinessParams()
constructor(originUrlString: string) {
super()
this.originUrlString = originUrlString
this.businessParams = new BusinessParams(this.originUrlString)
}
// invoke.ets
businessController: CustomDialogController | null = new CustomDialogController({
builder: BusinessDialog(this.urlString ?? ''),
autoCancel: true,
alignment: DialogAlignment.Bottom,
customStyle: true,
maskColor:'#ab4d4d4d'
})
问题:如果在自定义组件中实现自定义的构造方法 ?
支持命令式创建Web组件,这种方式创建的组件不会立即挂载到组件树,即不会对用户呈现(组件状态为Hidden和InActive),开发者可以在后续使用中按需动态挂载,看能否解决您的问题
参考文档:
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/web-page-loading-with-web-components-V5\#动态创建web组件
返回节点挂载在对应NodeContainer中
在对应NodeContainer创建的时候调用、或者通过rebuild方法调用刷新
您可参考如下文档,进行封装:
https://developer.huawei.com/consumer/cn/doc/best-practices-V5/bpta-ui-dynamic-operations-V5\#section1392174713107