在HarmonyOS NEXT开发中全局的loading组件?

在HarmonyOS NEXT开发中全局的loading组件?调接口前开启loading,接口结束时、关闭loading
想要loading弹窗代码全局直接可以引用,不用每个页面都写

阅读 617
1 个回答

目前暂不支持声明全局的CustomDialogController,CustomDialogController仅在作为@CustomDialog和@Component struct的成员变量,且在@Component struct内部定义时赋值才有效。
建议使用:promptAction.openCustomDialog,相关文档https://developer.huawei.com/consumer/cn/doc/harmonyos-refere...
对话框customDialogId要保持一致,建议使用全局变量,参考demo如下:

//index.ets 
import { promptAction } from '@kit.ArkUI' 
import { customDialogBuilder } from './components' 
 
AppStorage.setOrCreate('customDialogId', 0); 
@Entry 
@Component 
struct Index { 
  @State message: string = 'Hello World' 
  @StorageLink('customDialogId') customDialogId: number = 1; 
  build() { 
    Row() { 
      Column() { 
        Text(this.message) 
          .fontSize(50) 
          .fontWeight(FontWeight.Bold) 
          .onClick(() => { 
            promptAction.openCustomDialog({ 
              builder: customDialogBuilder.bind(this) 
            }).then((dialogId: number) => { 
              this.customDialogId = dialogId 
            }) 
          }) 
      } 
      .width('100%') 
    } 
    .height('100%') 
  } 
} 
 
//custom.ets 
import promptAction from '@ohos.promptAction' 
 
@Builder 
export function customDialogBuilder() { 
  Column() { 
    Text('Custom dialog Message').fontSize(10) 
    Row() { 
      Button("确认").onClick(() => { 
        promptAction.closeCustomDialog(AppStorage.get<number>('customDialogId')) 
      }) 
      Blank().width(50) 
      Button("取消").onClick(() => { 
        promptAction.closeCustomDialog(AppStorage.get<number>('customDialogId')) 
      }) 
    } 
  }.height(200).padding(5) 
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进