demo:async function myAsyncFunction(): Promise<string> { const result: string = await new Promise((resolve: Function) => { setTimeout(() => { resolve('Hello, world!'); }, 3000); }); console.info(result); // 输出: Hello, world! return result } @Entry @Component struct Index { @State message: string = 'Hello World'; build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) .onClick(async () => { let res = await myAsyncFunction(); console.info("res is: " + res); }) } .width('100%') } .height('100%') } }参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/async-concurrency-overview-V5\#asyncawait
demo:
参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/async-concurrency-overview-V5\#asyncawait