HarmonyOS NavDestination中使用LocalStorage无效的问题

项目中目前使用Navigation来做跳转。目前的问题是,用navigation打开的页面使用LocalStorage无效。

HarmonyOS
2024-12-20 16:43:12
1044浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
shlp

如果 用localStorage的话,@state修饰的关键词值的变化会导致页面跟着变化:

let para: Record<string, number> = { 'PropA': 47 };
let storage: LocalStorage = new LocalStorage(para);
@Entry(storage)
@Component
export default struct APage {
  @Consume('navigation') navigation: NavPathStack;
  @LocalStorageLink('PropA') storageLink: number =0;
  @State testid:number =0
  number: number = 0

  build() {
    NavDestination() {
      Column() {
        Text(JSON.stringify(this.testid))
          .fontSize("20vp")
          .textAlign(TextAlign.Center)
          .width('100%')
          .height("20vp")
          .onClick(() => {
            this.navigation.pushPath({
              name: "BPage"
            }, false);
          })

        Text("点击改变testId")
          .fontSize("20vp")
          .textAlign(TextAlign.Center)
          .width('100%')
          .height("20vp")
          .margin({top:'20vp'})
          .onClick(() => {
            this.number++
            storage.set('PropA', this.number)
            this.testid =  storage.get('PropA') as number
          })
      }
      .width("100%")
      .height('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.
  • 38.
  • 39.
  • 40.
  • 41.
分享
微博
QQ
微信
回复
2024-12-20 17:44:45
相关问题
如何在Navigation中使用LocalStorage
1172浏览 • 1回复 待解决
HarmonyOS NavDestinationexpandSafeArea问题
759浏览 • 1回复 待解决
HarmonyOS NavDestinationmenu问题
509浏览 • 1回复 待解决
HarmonyOS LocalStorage在Navgation内使用
690浏览 • 1回复 待解决
HarmonyOS Text 中使用 ImageSpan 问题
1167浏览 • 1回复 待解决
HarmonyOS LocalStorage.getShared()问题
946浏览 • 1回复 待解决
HarmonyOS NavDestination生命周期问题
667浏览 • 1回复 待解决
HarmonyOS navdestination页面返回按钮问题
1695浏览 • 1回复 待解决
HarmonyOS Token无效问题
579浏览 • 1回复 待解决
HarmonyOS Web组件使用localStorage报错
1681浏览 • 1回复 待解决
HarmonyOS 关于ArkTS中使用Rn搭建问题
1131浏览 • 1回复 待解决
jenkins容器中使用docker报错问题
8378浏览 • 2回复 待解决
HarmonyOS NavDestination和page使用区别
830浏览 • 1回复 待解决
HarmonyOS 使用navDestination报类型异常
519浏览 • 1回复 待解决