提交 1689bf8e 编写于 作者: J jiangbo

jiangbo91@huawei.com

add local_storage
Signed-off-by: Njiangbo <jiangbo91@huawei.com>
Change-Id: I7a350c2c58e00371dfef617eade74b92a4549caf
上级 f3a44851
...@@ -54,25 +54,25 @@ export default class MainAbility extends Ability { ...@@ -54,25 +54,25 @@ export default class MainAbility extends Ability {
console.log("[Demo MainAbility onCreate]"); console.log("[Demo MainAbility onCreate]");
globalThis.abilityWant = want; globalThis.abilityWant = want;
} }
onDestroy() { onDestroy() {
console.log("[Demo MainAbility onDestroy]") console.log("[Demo MainAbility onDestroy]")
} }
onWindowStageCreate(windowStage) { onWindowStageCreate(windowStage) {
// Main window is created,set main page for this ability // Main window is created,set main page for this ability
windowStage.setUlContent(this.context,"pages/index",this.storage) windowStage.setUlContent(this.context,"pages/index",this.storage)
} }
onWindowStageDestroy() { onWindowStageDestroy() {
// Main window is destroyed,release Ul related resources // Main window is destroyed,release Ul related resources
console.log("[Demo] MainAbility onWindoeStageDestroy") console.log("[Demo] MainAbility onWindoeStageDestroy")
} }
onForeground() { onForeground() {
// Ability has brought to foreground // Ability has brought to foreground
console.log("[Demo] MainAbility onForeground") console.log("[Demo] MainAbility onForeground")
} }
onBackground() { onBackground() {
// Ability has back to background // Ability has back to background
console.log("[Demo] MainAbility onBackground") console.log("[Demo] MainAbility onBackground")
}} }}
``` ```
获取页面: 获取页面:
...@@ -82,18 +82,18 @@ let storage = LocalStorage.GetShared() ...@@ -82,18 +82,18 @@ let storage = LocalStorage.GetShared()
@Entry(storage) @Entry(storage)
@Component @Component
struct LocalStorageComponent { struct LocalStorageComponent {
@LocalStorageLink("storageSimpleProp") simpleVarName: number = 0 @LocalStorageLink("storageSimpleProp") simpleVarName: number = 0
build() { build() {
Column(){ Column(){
Text(this.simpleVarName.toString()) Text(this.simpleVarName.toString())
.onClick(()=>{ .onClick(()=>{
this.simpleVarName +=1; this.simpleVarName +=1;
}) })
Text(JSON.stringify(this.simpleVarName)) Text(JSON.stringify(this.simpleVarName))
.fontSize(50) .fontSize(50)
} }
.height(500) .height(500)
} }
} }
``` ```
...@@ -102,22 +102,24 @@ struct LocalStorageComponent { ...@@ -102,22 +102,24 @@ struct LocalStorageComponent {
``` ```
let storage = new LocalStorage({"PropA":47}); let storage = new LocalStorage({"PropA":47});
@Entry(storage) @Entry(storage)
@Componentstruct ComA { @Componentstruct
@LocalStorageLink("PropA") storLink : number = 1; struct ComA {
build() { @LocalStorageLink("PropA") storLink : number = 1;
Column() { build() {
Text(`Parent from LocalStorage $(this.storLink)`) Column() {
.onClick(()=>this.storLink+=1) Text(`Parent from LocalStorage $(this.storLink)`) .onClick(()=>this.storLink+=1)
Child() Child()
} }
}} }
}
@Component @Component
struct Child{ struct Child{
@LocalStorageLink("PropA") storLink : number = 1; @LocalStorageLink("PropA") storLink : number = 1;
build() { build() {
Text(`Parent from LocalStorage $(this.storLink)`) Text(`Parent from LocalStorage $(this.storLink)`)
.onClick(()=>this.storLink1+=1) .onClick(()=>this.storLink1+=1)
}} }
}
``` ```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册