#鸿蒙学习大百科#如何实现一个NavPathStack的派生类?

如何实现一个NavPathStack的派生类?

HarmonyOS
2024-10-25 10:33:23
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
朝花惜拾丶
class MyNavPathStack extends NavPathStack {
  // usr defined property 'id'
  id: string = "__default__"

  // new function in derived class
  setId(id: string) {
    this.id = id;
  }
  getInfo(): string {
    return "this page used Derived NavPathStack, id: " + this.id
  }
  //重写NavPathStack的方法
  pushPath(info: NavPathInfo, animated?: boolean): void
  pushPath(info: NavPathInfo, options?: NavigationOptions): void
  pushPath(info: NavPathInfo, secArg?: boolean | NavigationOptions): void {
    console.log('[derive-test] reached DerivedNavPathStack\'s pushPath');
    if (typeof secArg === 'boolean') {
      super.pushPath(info, secArg);
    } else {
      super.pushPath(info, secArg);
    }
  }

  pop(animated?: boolean | undefined): NavPathInfo | undefined
  pop(result: Object, animated?: boolean | undefined): NavPathInfo | undefined
  pop(result?: Object, animated?: boolean | undefined): NavPathInfo | undefined {
    console.log('[derive-test] reached DerivedNavPathStack\'s pop');
    return super.pop(result, animated);
  }
}
分享
微博
QQ
微信
回复
2024-10-25 15:51:09
相关问题