HarmonyOS NavDestination中使用LocalStorage无效的问题

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

HarmonyOS
2024-12-20 16:43:12
浏览
收藏 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%')
    }
  }
}
分享
微博
QQ
微信
回复
2024-12-20 17:44:45
相关问题
如何在Navigation中使用LocalStorage
848浏览 • 1回复 待解决
HarmonyOS NavDestinationexpandSafeArea问题
322浏览 • 1回复 待解决
HarmonyOS NavDestinationmenu问题
176浏览 • 1回复 待解决
HarmonyOS LocalStorage在Navgation内使用
322浏览 • 1回复 待解决
HarmonyOS LocalStorage.getShared()问题
614浏览 • 1回复 待解决
HarmonyOS Text 中使用 ImageSpan 问题
821浏览 • 1回复 待解决
HarmonyOS Token无效问题
270浏览 • 1回复 待解决
HarmonyOS NavDestination生命周期问题
336浏览 • 1回复 待解决
HarmonyOS navdestination页面返回按钮问题
900浏览 • 1回复 待解决
HarmonyOS Web组件使用localStorage报错
1230浏览 • 1回复 待解决
HarmonyOS NavDestination和page使用区别
367浏览 • 1回复 待解决
HarmonyOS 使用navDestination报类型异常
166浏览 • 1回复 待解决
HarmonyOS 关于ArkTS中使用Rn搭建问题
650浏览 • 1回复 待解决
jenkins容器中使用docker报错问题
7914浏览 • 2回复 待解决