From c55ea6852ee6b7bacbf843a00b178164fd3aaf38 Mon Sep 17 00:00:00 2001 From: Bo Jiang Date: Thu, 8 Jun 2023 03:03:45 +0000 Subject: [PATCH] =?UTF-8?q?=E8=A3=85=E9=A5=B0=E5=99=A8=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=A3=B0=E6=98=8E=E4=B8=BAany=E4=BB=A5=E5=8F=8AlocalStorage?= =?UTF-8?q?=E7=88=B6=E5=AD=90=E6=A0=A1=E9=AA=8C=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bo Jiang --- .../OpenHarmony_4.0.8.2/changelogs-arkui.md | 97 ++++++++++--------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/zh-cn/release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-arkui.md b/zh-cn/release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-arkui.md index d2af605828..7baa6be3f4 100644 --- a/zh-cn/release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-arkui.md +++ b/zh-cn/release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-arkui.md @@ -4,30 +4,30 @@ 所有的状态装饰器变量需要显式声明变量类型,不允许声明any。 - **示例:** - - ```ts - // xxx.ets - @Entry - @Component - struct DatePickerExample { - // 错误写法: @State isLunar: any = false - @State isLunar: boolean = false - - build() { - ... - } - } - ``` +**示例:** + +```ts +// xxx.ets +@Entry +@Component +struct DatePickerExample { + // 错误写法: @State isLunar: any = false + @State isLunar: boolean = false + + build() { + ... + } +} +``` **变更影响** -如果状态装饰器变量没有显式声明变量类型,声明any,编译拦截报错。 +如果状态装饰器变量没有显式声明变量类型,声明any,编译拦截报错; - ```ts - // ArkTS:ERROR Please define an explicit type, not any. - @State isLunar: any = false - ``` +```ts +// ArkTS:ERROR Please define an explicit type, not any. +@State isLunar: any = false +``` **关键的接口/组件变更** @@ -35,40 +35,40 @@ **适配指导** -状态装饰器变量声明具体的变量类型替代any; +状态装饰器变量声明具体的变量类型替代any。 ## cl.arkui.2 自定义组件成员变量初始化的规则与约束。 -`@LocalStorageLink`, `@LocalStorageProp`修饰的变量不允许从父组件初始化。 +`@LocalStorageLink`, `@LocalStorageProp`修饰的变量不允许在父组件初始化。 **变更影响** -父组件初始化`@LocalStorageLink`, `@LocalStorageProp`修饰的变量,编译报错。 - - ```ts - @Entry - @Component - struct LocalStorageComponent { - build() { - Column() { - Child({ - /* ArkTS:ERROR Property 'simpleVarName' in the custom component 'Child' cannot - initialize here (forbidden to specify). */ - simpleVarName: 1, - /* ArkTS:ERROR Property 'objectName' in the custom component 'Child' cannot - initialize here (forbidden to specify). */ - objectName: new ClassA("x") - }) - } - } - } - @Component - struct Child { - @LocalStorageLink("storageSimpleProp") simpleVarName: number = 0; - @LocalStorageProp("storageObjectProp") objectName: ClassA = new ClassA("x"); - build() {} - } - ``` +不允许从父组件初始化`@LocalStorageLink`, `@LocalStorageProp`修饰的变量。 + +```ts +@Entry +@Component +struct LocalStorageComponent { + build() { + Column() { + Child({ + /* ArkTS:ERROR Property 'simpleVarName' in the custom component 'Child' cannot + initialize here (forbidden to specify). */ + simpleVarName: 1, + /* ArkTS:ERROR Property 'objectName' in the custom component 'Child' cannot + initialize here (forbidden to specify). */ + objectName: new ClassA("x") + }) + } + } +} +@Component +struct Child { + @LocalStorageLink("storageSimpleProp") simpleVarName: number = 0; + @LocalStorageProp("storageObjectProp") objectName: ClassA = new ClassA("x"); + build() {} +} +``` **关键的接口/组件变更** @@ -77,4 +77,5 @@ **适配指导** 构造子组件时,不对子组件的`@LocalStorageLink`, `@LocalStorageProp`修饰的变量进行赋值。 + 如果需要在父组件中修改子组件的`@LocalStorageLink`, `@LocalStorageProp`修饰的变量,则使用LocalStorage提供的API接口方法(比如set方法)赋值。 \ No newline at end of file -- GitLab