diff --git a/zh-cn/application-dev/quick-start/arkts-localstorage.md b/zh-cn/application-dev/quick-start/arkts-localstorage.md index 6be46e0843854f75aeac06aba8294187631a4a60..a8969c6239a68492d5b0f2aba098494d6e209dc1 100644 --- a/zh-cn/application-dev/quick-start/arkts-localstorage.md +++ b/zh-cn/application-dev/quick-start/arkts-localstorage.md @@ -322,71 +322,71 @@ Child自定义组件中的变化: 1. playCountLink的刷新会同步回LocalStorage,并且引起兄弟组件和父组件相应的刷新。 ```ts -class Data { - countStorage: number = 0; -} -let data: Data = { countStorage: 1 } -let storage = new LocalStorage(data); - -@Component -struct Child { - // 子组件实例的名字 - label: string = 'no name'; - // 和LocalStorage中“countStorage”的双向绑定数据 - @LocalStorageLink('countStorage') playCountLink: number = 0; - - build() { - Row() { - Text(this.label) - .width(50).height(60).fontSize(12) - Text(`playCountLink ${this.playCountLink}: inc by 1`) - .onClick(() => { - this.playCountLink += 1; - }) - .width(200).height(60).fontSize(12) - }.width(300).height(60) - } -} - -@Entry(storage) -@Component -struct Parent { - @LocalStorageLink('countStorage') playCount: number = 0; - - build() { - Column() { - Row() { - Text('Parent') - .width(50).height(60).fontSize(12) - Text(`playCount ${this.playCount} dec by 1`) - .onClick(() => { - this.playCount -= 1; - }) - .width(250).height(60).fontSize(12) - }.width(300).height(60) - - Row() { - Text('LocalStorage') - .width(50).height(60).fontSize(12) - Text(`countStorage ${this.playCount} incr by 1`) - .onClick(() => { - let countStorage: number | undefined = storage.get('countStorage'); - if (countStorage != undefined){ - countStorage += 1; - storage.set('countStorage', countStorage); - } - }) - .width(250).height(60).fontSize(12) - }.width(300).height(60) - - Child({ label: 'ChildA' }) - Child({ label: 'ChildB' }) - - Text(`playCount in LocalStorage for debug ${storage.get('countStorage')}`) - .width(300).height(60).fontSize(12) - } - } -} + class Data { + countStorage: number = 0; + } + let data: Data = { countStorage: 1 } + let storage = new LocalStorage(data); + + @Component + struct Child { + // 子组件实例的名字 + label: string = 'no name'; + // 和LocalStorage中“countStorage”的双向绑定数据 + @LocalStorageLink('countStorage') playCountLink: number = 0; + + build() { + Row() { + Text(this.label) + .width(50).height(60).fontSize(12) + Text(`playCountLink ${this.playCountLink}: inc by 1`) + .onClick(() => { + this.playCountLink += 1; + }) + .width(200).height(60).fontSize(12) + }.width(300).height(60) + } + } + + @Entry(storage) + @Component + struct Parent { + @LocalStorageLink('countStorage') playCount: number = 0; + + build() { + Column() { + Row() { + Text('Parent') + .width(50).height(60).fontSize(12) + Text(`playCount ${this.playCount} dec by 1`) + .onClick(() => { + this.playCount -= 1; + }) + .width(250).height(60).fontSize(12) + }.width(300).height(60) + + Row() { + Text('LocalStorage') + .width(50).height(60).fontSize(12) + Text(`countStorage ${this.playCount} incr by 1`) + .onClick(() => { + let countStorage: number | undefined = storage.get('countStorage'); + if (countStorage != undefined){ + countStorage += 1; + storage.set('countStorage', countStorage); + } + }) + .width(250).height(60).fontSize(12) + }.width(300).height(60) + + Child({ label: 'ChildA' }) + Child({ label: 'ChildB' }) + + Text(`playCount in LocalStorage for debug ${storage.get('countStorage')}`) + .width(300).height(60).fontSize(12) + } + } + } ```