Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
28458a5f
D
Docs
项目概览
OpenHarmony
/
Docs
接近 2 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
28458a5f
编写于
9月 04, 2023
作者:
1
189******51
提交者:
Gitee
9月 04, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update zh-cn/application-dev/quick-start/arkts-localstorage.md.
Signed-off-by:
N
189******51
<
lipeicheng5@huawei.com
>
上级
0572a613
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
55 addition
and
55 deletion
+55
-55
zh-cn/application-dev/quick-start/arkts-localstorage.md
zh-cn/application-dev/quick-start/arkts-localstorage.md
+55
-55
未找到文件。
zh-cn/application-dev/quick-start/arkts-localstorage.md
浏览文件 @
28458a5f
...
@@ -192,37 +192,37 @@ link1.set(49); // two-way sync: link1.get() == link2.get() == prop.get() == 49
...
@@ -192,37 +192,37 @@ link1.set(49); // two-way sync: link1.get() == link2.get() == prop.get() == 49
-
\@
LocalStorageLink绑定LocalStorage对给定的属性,建立双向数据同步。
-
\@
LocalStorageLink绑定LocalStorage对给定的属性,建立双向数据同步。
```
ts
```
ts
// 创建新实例并使用给定对象初始化
// 创建新实例并使用给定对象初始化
let
storage
=
new
LocalStorage
();
let
storage
=
new
LocalStorage
();
storage
[
'
PropA
'
]
=
47
;
storage
[
'
PropA
'
]
=
47
;
@
Component
@
Component
struct
Child
{
struct
Child
{
// @LocalStorageLink变量装饰器与LocalStorage中的'PropA'属性建立双向绑定
// @LocalStorageLink变量装饰器与LocalStorage中的'PropA'属性建立双向绑定
@
LocalStorageLink
(
'
PropA
'
)
storLink2
:
number
=
1
;
@
LocalStorageLink
(
'
PropA
'
)
storLink2
:
number
=
1
;
build
()
{
build
()
{
Button
(
`Child from LocalStorage
${
this
.
storLink2
}
`
)
Button
(
`Child from LocalStorage
${
this
.
storLink2
}
`
)
// 更改将同步至LocalStorage中的'PropA'以及Parent.storLink1
// 更改将同步至LocalStorage中的'PropA'以及Parent.storLink1
.
onClick
(()
=>
this
.
storLink2
+=
1
)
.
onClick
(()
=>
this
.
storLink2
+=
1
)
}
}
}
}
// 使LocalStorage可从@Component组件访问
// 使LocalStorage可从@Component组件访问
@
Entry
(
storage
)
@
Entry
(
storage
)
@
Component
@
Component
struct
CompA
{
struct
CompA
{
// @LocalStorageLink变量装饰器与LocalStorage中的'PropA'属性建立双向绑定
// @LocalStorageLink变量装饰器与LocalStorage中的'PropA'属性建立双向绑定
@
LocalStorageLink
(
'
PropA
'
)
storLink1
:
number
=
1
;
@
LocalStorageLink
(
'
PropA
'
)
storLink1
:
number
=
1
;
build
()
{
build
(
)
{
Column
({
space
:
15
}
)
{
Column
({
space
:
15
})
{
Button
(
`Parent from LocalStorage
${
this
.
storLink1
}
`
)
// initial value from LocalStorage will be 47, because 'PropA' initialized already
Button
(
`Parent from LocalStorage
${
this
.
storLink1
}
`
)
// initial value from LocalStorage will be 47, because 'PropA' initialized already
.
onClick
(()
=>
this
.
storLink1
+=
1
)
.
onClick
(()
=>
this
.
storLink1
+=
1
)
// @Component子组件自动获得对CompA LocalStorage实例的访问权限。
// @Component子组件自动获得对CompA LocalStorage实例的访问权限。
Child
()
Child
()
}
}
}
}
}
}
```
```
...
@@ -235,39 +235,39 @@ struct CompA {
...
@@ -235,39 +235,39 @@ struct CompA {
-
Child组件中,Text绑定的storProp2 依旧显示47。
-
Child组件中,Text绑定的storProp2 依旧显示47。
```
ts
```
ts
// 创建新实例并使用给定对象初始化
// 创建新实例并使用给定对象初始化
let
storage
=
new
LocalStorage
();
let
storage
=
new
LocalStorage
();
storage
[
'
PropA
'
]
=
47
;
storage
[
'
PropA
'
]
=
47
;
// 使LocalStorage可从@Component组件访问
// 使LocalStorage可从@Component组件访问
@
Entry
(
storage
)
@
Entry
(
storage
)
@
Component
@
Component
struct
CompA
{
struct
CompA
{
// @LocalStorageProp变量装饰器与LocalStorage中的'PropA'属性建立单向绑定
// @LocalStorageProp变量装饰器与LocalStorage中的'PropA'属性建立单向绑定
@
LocalStorageProp
(
'
PropA
'
)
storProp1
:
number
=
1
;
@
LocalStorageProp
(
'
PropA
'
)
storProp1
:
number
=
1
;
build
()
{
build
()
{
Column
({
space
:
15
})
{
Column
({
space
:
15
})
{
// 点击后从47开始加1,只改变当前组件显示的storProp1,不会同步到LocalStorage中
// 点击后从47开始加1,只改变当前组件显示的storProp1,不会同步到LocalStorage中
Button
(
`Parent from LocalStorage
${
this
.
storProp1
}
`
)
Button
(
`Parent from LocalStorage
${
this
.
storProp1
}
`
)
.
onClick
(()
=>
this
.
storProp1
+=
1
)
.
onClick
(()
=>
this
.
storProp1
+=
1
)
Child
()
Child
()
}
}
}
}
}
}
@
Component
@
Component
struct
Child
{
struct
Child
{
// @LocalStorageProp变量装饰器与LocalStorage中的'PropA'属性建立单向绑定
// @LocalStorageProp变量装饰器与LocalStorage中的'PropA'属性建立单向绑定
@
LocalStorageProp
(
'
PropA
'
)
storProp2
:
number
=
2
;
@
LocalStorageProp
(
'
PropA
'
)
storProp2
:
number
=
2
;
build
()
{
build
()
{
Column
({
space
:
15
})
{
Column
({
space
:
15
})
{
// 当CompA改变时,当前storProp2不会改变,显示47
// 当CompA改变时,当前storProp2不会改变,显示47
Text
(
`Parent from LocalStorage
${
this
.
storProp2
}
`
)
Text
(
`Parent from LocalStorage
${
this
.
storProp2
}
`
)
}
}
}
}
}
}
```
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录