HarmonyOS加载在线网址
实现步骤:
- 定义一个页面,可以根据路由参数,来显示页面标题和加载的页面
-
- 页面名称: WebPage
- 参数: title(页面标题), src(页面路径) , 参数对象类型: WebPageParams
- 使用
-
- 用户协议: Pass Interview
- 隐私政策: Pass Interview
// xxx.ets
import { webview } from '@kit.ArkWeb';
@Entry
@Component
struct WebComponent {
controller: webview.WebviewController = new webview.WebviewController();
build() {
Column() {
Web({ src: 'www.example.com', controller: this.controller })
}
}
}
封装Web页面
import { HcNavBar } from '../commons/components/HcNavBar'
import { webview } from '@kit.ArkWeb'
import { router } from '@kit.ArkUI'
interface WebPageParams {
title: string
src: string
}
@Entry
@Component
struct WebPage {
@State title: string = ''
@State src: string = ''
controller = new webview.WebviewController()
aboutToAppear(): void {
const params = router.getParams() as WebPageParams
this.title = params.title
this.src = params.src
}
build() {
Column() {
HcNavBar({ title: this.title, showRightIcon: false })
Web({ src: this.src, controller: this.controller })
.width('100%')
.layoutWeight(1)
}
.height('100%')
.width('100%')
}
}
HarmonyOS API12以上加载在线网址
16万+

被折叠的 条评论
为什么被折叠?



