HarmonyOS 有subwindow的情况下跳转到了其他subwindow上了

HarmonyOS
2024-12-24 16:34:10
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
fox280

采用router跳转页面的时候是全局性的并没有和某个ui实例绑定,在多实例场景下使用比较混乱导致实例获取接口行为不一致。推荐使用this.getUIContext().getRouter().pushNamedRoute,示例如下:

import { display, router } from '@kit.ArkUI';
import LJWaterMarkWindow from '../entryability/WindowManager';
import { requestPermission } from './Permission';

@Entry
@Component
struct Index {
  @State message: string = '请求权限后,跳转下一个页面';
  windowWidth: number = display.getDefaultDisplaySync().width;
  windowHeight: number = display.getDefaultDisplaySync().height;

  aboutToAppear(): void {
    LJWaterMarkWindow.showWaterWindowWithWindowStage()
  }

  middleMethod(): Promise<void> {
    return new Promise((res) => {
      // res();
      setTimeout(res, 2000)
    })
  }

  build() {
    Column({ space: 20 }) {
      Text(this.message).onClick(() => {
        requestPermission().then(() => {
          this.middleMethod().then(() => {
            this.getUIContext().getRouter().pushNamedRoute({ name: 'second' })
          })
        })
      })
    }
    .justifyContent(FlexAlign.Center)
    .height('100%')
    .width('100%')
  }
}
  • 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.
  • 35.
  • 36.
  • 37.
分享
微博
QQ
微信
回复
2024-12-24 19:36:53
相关问题
HarmonyOS subwindow问题
408浏览 • 1回复 待解决
HarmonyOS subWindow如何加载UI
349浏览 • 1回复 待解决
如何监听subwindow生命周期
966浏览 • 1回复 待解决
HarmonyOS 如何设置SubWindow背景颜色
560浏览 • 1回复 待解决
HarmonyOS 手机静音情况下,无法震动
955浏览 • 1回复 待解决
ForEach什么情况下会触发复用
1544浏览 • 2回复 待解决
HarmonyOS 哪些情况下主窗口不存在
570浏览 • 1回复 待解决