From 8c5fe17ae789c71a1d1e2e1464873f4afd8005d4 Mon Sep 17 00:00:00 2001 From: Haoming Luo Date: Mon, 31 Jul 2023 15:13:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9'=E5=AF=BC=E5=87=BAHSP?= =?UTF-8?q?=E5=86=85=E8=B5=84=E6=BA=90'=E9=83=A8=E5=88=86=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Haoming Luo --- zh-cn/application-dev/quick-start/in-app-hsp.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zh-cn/application-dev/quick-start/in-app-hsp.md b/zh-cn/application-dev/quick-start/in-app-hsp.md index 48d1bfd78f..24bdd8551a 100644 --- a/zh-cn/application-dev/quick-start/in-app-hsp.md +++ b/zh-cn/application-dev/quick-start/in-app-hsp.md @@ -98,10 +98,10 @@ export { MyTitleBar } from './components/MyTitleBar' ```ts // library/src/main/ets/ResManager.ets export class ResManager{ - static getPic(){ + static getPic(): Resource{ return $r("app.media.pic"); } - static getDesc(){ + static getDesc(): Resource{ return $r("app.string.shared_desc"); } } @@ -162,12 +162,12 @@ struct Index { Log.info("add button click!"); this.message = "result: " + add(1, 2); }) + // ResManager返回的Resource对象,可以传给组件直接使用,也可以从中取出资源来使用 Image(ResManager.getPic()) .width("100%") Button('getStringValue') .onClick(()=> { // 先通过当前上下文获取hsp模块的上下文,再获取hsp模块的resourceManager,然后再调用resourceManager的接口获取资源 - // 注:用`$r`方法获得的是Resource对象形式的资源,其可被组件直接使用,但在此须对其进行解封装才可使用 getContext().createModuleContext('library').resourceManager.getStringValue(ResManager.getDesc()) .then(value => { console.log("getStringValue is " + value); -- GitLab