在页面中获取Context包含两个步骤,第一步导入依赖资源包,第二步通过getContext函数获取UIAbilityContext。import { common } from '@kit.AbilityKit'; @Entry @Component struct Index { private context = getContext(this) as common.UIAbilityContext; // ... // 页面展示 build() { // ... } }本文参与了思否 HarmonyOS 技术问答马拉松,欢迎正在阅读的你也加入。
在页面中获取Context包含两个步骤,第一步导入依赖资源包,第二步通过getContext函数获取UIAbilityContext。