未验证 提交 40dc9666 编写于 作者: 1 189******51 提交者: Gitee

update zh-cn/application-dev/quick-start/arkts-localstorage.md.

Signed-off-by: N189******51 <lipeicheng5@huawei.com>
上级 b5109e35
......@@ -191,12 +191,12 @@ link1.set(49); // two-way sync: link1.get() == link2.get() == prop.get() == 49
- \@LocalStorageLink绑定LocalStorage对给定的属性,建立双向数据同步。
```ts
// 创建新实例并使用给定对象初始化
let storage = new LocalStorage();
storage['PropA'] = 47;
// 创建新实例并使用给定对象初始化
let storage = new LocalStorage();
storage['PropA'] = 47;
@Component
struct Child {
@Component
struct Child {
// @LocalStorageLink变量装饰器与LocalStorage中的'PropA'属性建立双向绑定
@LocalStorageLink('PropA') storLink2: number = 1;
......@@ -205,11 +205,11 @@ struct Child {
// 更改将同步至LocalStorage中的'PropA'以及Parent.storLink1
.onClick(() => this.storLink2 += 1)
}
}
// 使LocalStorage可从@Component组件访问
@Entry(storage)
@Component
struct CompA {
}
// 使LocalStorage可从@Component组件访问
@Entry(storage)
@Component
struct CompA {
// @LocalStorageLink变量装饰器与LocalStorage中的'PropA'属性建立双向绑定
@LocalStorageLink('PropA') storLink1: number = 1;
......@@ -221,7 +221,7 @@ struct CompA {
Child()
}
}
}
}
```
......@@ -234,14 +234,14 @@ struct CompA {
- Child组件中,Text绑定的storProp2 依旧显示47。
```ts
// 创建新实例并使用给定对象初始化
let storage = new LocalStorage();
storage['PropA'] = 47;
// 创建新实例并使用给定对象初始化
let storage = new LocalStorage();
storage['PropA'] = 47;
// 使LocalStorage可从@Component组件访问
@Entry(storage)
@Component
struct CompA {
// 使LocalStorage可从@Component组件访问
@Entry(storage)
@Component
struct CompA {
// @LocalStorageProp变量装饰器与LocalStorage中的'PropA'属性建立单向绑定
@LocalStorageProp('PropA') storProp1: number = 1;
......@@ -253,10 +253,10 @@ struct CompA {
Child()
}
}
}
}
@Component
struct Child {
@Component
struct Child {
// @LocalStorageProp变量装饰器与LocalStorage中的'PropA'属性建立单向绑定
@LocalStorageProp('PropA') storProp2: number = 2;
......@@ -266,7 +266,7 @@ struct Child {
Text(`Parent from LocalStorage ${this.storProp2}`)
}
}
}
}
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册