可参考下面代码:import { BusinessError } from '@ohos.base'; import { ComponentContent } from "@ohos.arkui.node"; class Params { text: string = "" constructor(text: string) { this.text = text; } }//传参 @Builder function buildText(params: Params) { Row(){ Column() { Text(params.text) .fontSize(50) .fontWeight(FontWeight.Bold) .margin({bottom: 36}) }.backgroundColor('#FFF0F0F0') } .height("100%") } //自定义组件的内容 @Entry @Component struct Index { @State message: string = "显示TOAST" build() { Row() { Column() { Button("click me") .onClick(() => { let uiContext = this.getUIContext(); let promptAction = uiContext.getPromptAction(); let contentNode = new ComponentContent(uiContext, wrapBuilder(buildText), new Params(this.message));//上下文、自定义节点、传参 try { promptAction.openCustomDialog(contentNode); } catch (error) { let message = (error as BusinessError).message; let code = (error as BusinessError).code; console.error(`OpenCustomDialog args error code is ${code}, message is ${message}`); }; }) } .width('100%') .height('100%') } .height('100%') } }
可参考下面代码: