Arkts web组件的使用

访问在线网页时您需要在module.json5文件中申明网络访问权限:ohos.permission.INTERNET。

加载网页效果无法在预览器中查看,需要在模拟器或者真机中展示项目

Web组件的使用非常简单,只需要ArkTS文件中创建一个Web组件,传入两个参数就可以了。其中src指定引用的网页路径,controller为组件的控制器,通过controller绑定Web组件,用于实现对Web组件的控制

// 使用web组件加载网页
import webview from '@ohos.web.webview'
@Entry
@Component
struct WebComp {
  controll:WebviewController = new webview.WebviewController()
  build() {
    Row() {
      Column() {
        Web({
          src:'https://www.bilibili.com/video/BV16X4y1g7wT/?spm_id_from=333.934.0.0',
          controller:this.controll
        })
      }
      .width('100%')
    }
    .height('100%')
  }
}

详细使用见官网

Web-ArkTS API参考-HarmonyOS应用开发

猜你喜欢

转载自blog.csdn.net/qq_34491508/article/details/134653949