鸿蒙Harmony应用开发—ArkTS声明式开发(基础手势:Web)上篇

本文介绍了鸿蒙HarmonyOS应用开发中 ArkTS 声明式开发的基础手势配置,涉及Webview的相关属性,如文件访问、JavaScript权限、图片加载、手势缩放等,并提供了示例代码。文章还提到了一份完整的HarmonyOS鸿蒙开发学习资料,旨在帮助开发者提升技能。
摘要由CSDN通过智能技术生成

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数HarmonyOS鸿蒙开发工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年HarmonyOS鸿蒙开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img

img
img
htt

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上HarmonyOS鸿蒙开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新

如果你觉得这些内容对你有帮助,可以添加VX:vip204888 (备注鸿蒙获取)
img

一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

public static getContext(): GlobalContext {
if (!GlobalContext.instance) {
GlobalContext.instance = new GlobalContext();
}
return GlobalContext.instance;
}

getObject(value: string): Object | undefined {
return this._objects.get(value);
}

setObject(key: string, objectClass: Object): void {
this._objects.set(key, objectClass);
}
}

 

// xxx.ets
import web_webview from ‘@ohos.web.webview’
import { GlobalContext } from ‘…/GlobalContext’

let url = ‘file://’ + GlobalContext.getContext().getObject(“filesDir”) + ‘/index.html’

@Entry
@Component
struct WebComponent {
controller: web_webview.WebviewController = new web_webview.WebviewController()
build() {
Column() {
// 加载沙箱路径文件。
Web({ src: url, controller: this.controller })
}
}
}

2. 修改EntryAbility.ts。

 以filesDir为例,获取沙箱路径。若想获取其他路径,请参考[应用文件路径]( )。

 

// xxx.ts
import UIAbility from ‘@ohos.app.ability.UIAbility’;
import AbilityConstant from ‘@ohos.app.ability.AbilityConstant’;
import Want from ‘@ohos.app.ability.Want’;
import web_webview from ‘@ohos.web.webview’;
import { GlobalContext } from ‘…/GlobalContext’

export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
// 通过在GlobalContext对象上绑定filesDir,可以实现UIAbility组件与UI之间的数据同步。
GlobalContext.getContext().setObject(“filesDir”, this.context.filesDir);
console.log("Sandbox path is " + GlobalContext.getContext().getObject(“filesDir”))
}
}

 加载的html文件。

 

Hello World

```

属性

通用属性仅支持aspectRatiobackdropBlurbackgroundColorbindContentCoverbindContextMenubindMenubindSheetborderColorborderRadiusborderStyleborderWidthclipconstraintSizedefaultFocusfocusabletabIndexgroupDefaultFocusfocusOnTouchdisplayPriorityenabledflexBasisflexGrowflexShrinklayoutWeightidgridOffsetgridSpanuseSizeTypeheighttouchablemarginmarkAnchoroffsetwidthzIndexvisibilityscaletransformresponseRegionsizestateStylesopacityshadowsharedTransitiontransition

domStorageAccess

domStorageAccess(domStorageAccess: boolean)

设置是否开启文档对象模型存储接口(DOM Storage API)权限,默认未开启。

系统能力: SystemCapability.Web.Webview.Core

参数:

参数名 参数类型 必填 默认值 参数描述
domStorageAccess boolean false 设置是否开启文档对象模型存储接口(DOM Storage API)权限。

示例:

// xxx.ets
import web_webview from '@ohos.web.webview'

@Entry
@Component
struct WebComponent {
  controller: web_webview.WebviewController = new web_webview.WebviewController()
  build() {
    Column() {
      Web({ src: 'www.example.com', controller: this.controller })
        .domStorageAccess(true)
    }
  }
}
fileAccess

fileAccess(fileAccess: boolean)

设置是否开启应用中文件系统的访问,默认启用。$rawfile(filepath/filename)")中rawfile路径的文件不受该属性影响而限制访问。

参数:

参数名 参数类型 必填 默认值 参数描述
fileAccess boolean true 设置是否开启应用中文件系统的访问,默认启用。

示例:

// xxx.ets
import web_webview from '@ohos.web.webview'

@Entry
@Component
struct WebComponent {
  controller: web_webview.WebviewController = new web_webview.WebviewController()
  build() {
    Column() {
      Web({ src: 'www.example.com', controller: this.controller })
        .fileAccess(true)
    }
  }
}
imageAccess

imageAccess(imageAccess: boolean)

设置是否允许自动加载图片资源,默认允许。

参数:

参数名 参数类型 必填 默认值 参数描述
  • 26
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值