如果 用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%') } } }
如果 用localStorage的话,@state修饰的关键词值的变化会导致页面跟着变化: