HarmonyOS ArkTS接口回调的案例

ArkTS接口回调的声明案例如何编写。

HarmonyOS
2024-10-21 10:15:39
1481浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

demo如下:

//MyInterDemo.ets

export interface MyInterDemo {  
  func_1: () => void;  
  func_2: () => boolean;  
  func_3: (arg: string) => void;  
}  
  
//TestInterfacePage.ets  
import { MyInterDemo } from ‘…/interface/MyInterDemo’  
  
@Entry  
@Component  
struct TestInterfacePage {  
  
  testInter(inter: MyInterDemo) {  
    console.log(‘testInter’);  
    inter.func_1();  
    inter.func_2();  
    inter.func_3(‘hello’);  
  }  
  
  build() {  
    Row() {  
      Column() {  
        Button(‘Test interface’)  
        .onClick(() => {  
          let demo: MyInterDemo = {  
            func_1: () => {  
              console.log(‘func_1’);  
            },  
            func_2: () => {  
              console.log(‘func_2’);  
              return true;  
            },  
            func_3: (arg: string) => {  
              console.log(‘func_3:’ + arg);  
            }  
          }  
          this.testInter(demo);  
        })  
      }  
      .width(‘100%’)  
    }  
    .height(‘100%’)  
  }  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
分享
微博
QQ
微信
回复
2024-10-21 17:18:27


相关问题
HarmonyOS ArkTS接口案例问题
2242浏览 • 1回复 待解决
HarmonyOS 接口写法
928浏览 • 1回复 待解决
接口内定义匿名语法
2517浏览 • 1回复 待解决
HarmonyOS 事件
1033浏览 • 1回复 待解决
HarmonyOS killAllProcesses()无成功
855浏览 • 1回复 待解决
HarmonyOS 点击事件方法
1041浏览 • 1回复 待解决
HarmonyOS Watch没有
808浏览 • 1回复 待解决
HarmonyOS onNewWant未
619浏览 • 1回复 待解决
HarmonyOS Web组件
1197浏览 • 1回复 待解决
HarmonyOS 人脸识别问题
838浏览 • 1回复 待解决
HarmonyOS onAreaChange方法问题
974浏览 • 1回复 待解决