弹窗的入门典型案例 this.getUIContext().showAlertDialog()

hm688c71f270444
发布于 2025-9-29 11:12
浏览
0收藏

弹窗的入门典型案例 this.getUIContext().showAlertDialog()-鸿蒙开发者社区cke_141.png

代码如下:

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';

  build() {
    Column() {
      Button('删除',{type:ButtonType.Normal})
        .fontSize(18)
        .width(80)
        .margin(10)
        .padding(10)
        .onClick(() => {
          this.getUIContext().showAlertDialog({
            title: '确认删除',
            message: '确定要删除吗?',
            primaryButton: {
              value: '删除',
              action: ()=>{}
            },
            secondaryButton:{
              value:'取消',
              action: ()=>{}
            }
          })
        })
    }
    .width('100%')
  }
}

分类
标签
收藏
回复
举报
回复
    相关推荐