中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何实现对LocalStorage的实时监听?
微信扫码分享
let para: Record<string, number> = { 'PropA': 47 }; let storage: LocalStorage = new LocalStorage(para); @Entry(storage) @Component struct Index { build() { Column() { Button("CLick").onClick(() => {//点击按钮改变PropA的值 storage.set("PropA", 60) }) Child() }.height("100%") .alignItems(HorizontalAlign.Center) .justifyContent(FlexAlign.Center) } } @Component export struct Child { @LocalStorageProp("PropA") @Watch("onChange") aa: number = 0 onChange() { console.log("===========PropA:发生了变化") } }