HarmonyOS Navigation组件入栈打开新页面web内容显示异常问题

代码如下:

入口页面Index

import { page1 } from '../test/page1'
import { page2 } from '../test/page2';

@Entry
@Component
struct Index {
  @Provide('navPathStack') navPathStack: NavPathStack = new NavPathStack();

  @Builder
  myRouter(name: string, param?: Object) {
    if (name === 'page1') {
      page1()
    } else if (name === 'page2') {
      page2()
    }
  }

  build() {
    Navigation(this.navPathStack) {
      Column() {
        Button('跳转page1')
          .onClick(() => {
            this.navPathStack.pushPathByName('page1', null)
          })
      }
      .alignItems(HorizontalAlign.Center)
      .justifyContent(FlexAlign.Center)
      .layoutWeight(1)
    }
    .hideTitleBar(false)
    .hideToolBar(true)
    .navDestination(this.myRouter)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.

中间页面page1

import web_webview from '@ohos.web.webview'

@Component
export struct page1 {
  @Consume('navPathStack') navPathStack: NavPathStack

  build() {
    NavDestination() {
      Column() {
        Button('跳转page2')
          .onClick(() => {
            this.navPathStack.pushPathByName('page2', null)
          })
      }
      .alignItems(HorizontalAlign.Center)
      .justifyContent(FlexAlign.Center)
      .layoutWeight(1)
    }
    .hideTitleBar(false)
    .onReady((ctx: NavDestinationContext) => {
    })
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.

web页面page2

import web_webview from '@ohos.web.webview'

@Component
export struct page2 {
  controller: web_webview.WebviewController = new web_webview.WebviewController()

  build() {
    NavDestination() {
      Column() {
        Web({ src: 'xxx', controller: this.controller })
          .zIndex(1).width('100%').height('100%')
      }.height('100%').width('100%')
      .backgroundColor(Color.Gray)
    }
    .hideTitleBar(false)
    .onReady((ctx: NavDestinationContext) => {
    })
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.

启动app依次打开页面Index->page1->page2,此时web显示正常。返回page1后再次打开page2此时web显示异常,web顶端有部分页面消失、无法滚动显示、弹性滚动下拉可显示。

HarmonyOS
2024-12-25 14:17:12
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
shlp

参考示例如下:

Web({ src: 'xxx', controller: this.controller }).expandSafeArea()
  .zIndex(1).width('100%').height('100%')
  • 1.
  • 2.
分享
微博
QQ
微信
回复
2024-12-25 16:52:33
相关问题
HarmonyOS 如何刷新页面内容
604浏览 • 1回复 待解决
HarmonyOS Navigation先pop再push新页面失败
568浏览 • 1回复 待解决
如何更新页面列表数据
7937浏览 • 1回复 待解决
HarmonyOS web页面显示异常
575浏览 • 1回复 待解决
HarmonyOS 数据改变未刷新页面
1299浏览 • 0回复 待解决
dialog跳转新页面返回后dialog关闭
1008浏览 • 1回复 待解决
HarmonyOS web组件 加载web页面异常
1204浏览 • 1回复 待解决
怎么在进度条更新的时候刷新页面
5566浏览 • 1回复 待解决