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

本文详细介绍了在鸿蒙HarmonyOS中使用ArkTS进行声明式Web应用开发时,如何配置各种手势及权限,包括domStorageAccess、fileAccess、imageAccess等。通过示例代码展示了如何开启和使用这些功能,以便开发者更好地控制Web应用的行为和安全。
摘要由CSDN通过智能技术生成

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

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

img
img
htt

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

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

如果你需要这些资料,可以添加V获取:vip204888 (备注鸿蒙)
img

正文

Column() {
// 加载沙箱路径文件。
Web({ src: url, controller: this.controller })
}
}
}

  1. 修改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)

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

参数:

参数名 参数类型 必填 默认值 参数描述
imageAccess 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 })
.imageAccess(true)
}
}
}

javaScriptProxy

javaScriptProxy(javaScriptProxy: { object: object, name: string, methodList: Array, controller: WebviewController | WebController})

注入JavaScript对象到window对象中,并在window对象中调用该对象的方法。所有参数不支持更新。此接口只支持注册一个对象,若需要注册多个对象请使用registerJavaScriptProxy9+

参数:

参数名 参数类型 必填 默认值 参数描述
object object - 参与注册的对象。只能声明方法,不能声明属性。
name string - 注册对象的名称,与window中调用的对象名一致。
m
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值