如何在UI中获取Context

如何在UI中获取Context

HarmonyOS
2024-01-20 09:52:09
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
素年锦时静待君丶

在页面中获取Context包含两个步骤,第一步导入依赖资源包,第二步通过getContext函数获取UIAbilityContext。

import { common } from '@kit.AbilityKit';  
 
@Entry @Component struct Index {  
  private context = getContext(this) as common.UIAbilityContext;    
  // ...     
  // 页面展示  
  build() {    
    // ... 
  } 
}

参考文档

UIAbility组件基本用法

分享
微博
QQ
微信
回复
2024-01-20 23:23:57
提问
该提问已有0人参与 ,帮助了0人