From 9a4897f7e869dfbe355f67f339234113ac5a5ea5 Mon Sep 17 00:00:00 2001 From: "OWNEROR-41FNVD0\\lenovo" Date: Thu, 8 May 2025 14:42:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=9F=E5=BC=83api=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/Index.ets | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 0ed9e40..bb929db 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -22,7 +22,7 @@ import { promptAction } from '@kit.ArkUI'; struct Index { @State message: string = ''; @State content: string = ''; - private context = getContext(this) as common.UIAbilityContext; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; private path = this.context.filesDir + '/text.txt'; build() { @@ -58,7 +58,12 @@ struct Index { .margin({ top: 12 }) .onClick(() => { fileNapi.write(this.path, this.message); - promptAction.showToast({ message: $r('app.string.written_successfully'), showMode: promptAction.ToastShowMode.DEFAULT }); + this.getUIContext() + .getPromptAction() + .showToast({ + message: $r('app.string.written_successfully'), + showMode: promptAction.ToastShowMode.DEFAULT + }); }) Text($r('app.string.read_data')) @@ -81,7 +86,8 @@ struct Index { .margin({ top: 12 }) .onClick(() => { this.content = fileNapi.read(this.path); - promptAction.showToast({ message: $r('app.string.read_successfully') }); + this.getUIContext() + .getPromptAction().showToast({ message: $r('app.string.read_successfully') }); }) } .padding({ -- Gitee