未验证 提交 7b1de676 编写于 作者: O openharmony_ci 提交者: Gitee

!19417 modify changlog

Merge pull request !19417 from Bo Jiang/changlog
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
## cl.arkui.1 状态变量数据类型声明使用限制。 ## cl.arkui.1 状态变量数据类型声明使用限制。
1. 所有的状态装饰器变量需要显式声明变量类型,不允许声明any,不支持Date数据类型 1. 所有的状态装饰器变量需要显式声明变量类型,不允许声明any。
示例: 示例:
...@@ -13,34 +13,13 @@ ...@@ -13,34 +13,13 @@
struct DatePickerExample { struct DatePickerExample {
// 错误写法: @State isLunar: any = false // 错误写法: @State isLunar: any = false
@State isLunar: boolean = false @State isLunar: boolean = false
// 错误写法: @State selectedDate: Date = new Date('2021-08-08')
private selectedDate: Date = new Date('2021-08-08')
build() { build() {
Column() { ...
Button('切换公历农历')
.margin({ top: 30 })
.onClick(() => {
this.isLunar = !this.isLunar
})
DatePicker({
start: new Date('1970-1-1'),
end: new Date('2100-1-1'),
selected: this.selectedDate
})
.lunar(this.isLunar)
.onChange((value: DatePickerResult) => {
this.selectedDate.setFullYear(value.year, value.month, value.day)
console.info('select current date is: ' + JSON.stringify(value))
})
}.width('100%')
} }
} }
``` ```
![datePicker](../../../application-dev/reference/arkui-ts/figures/datePicker.gif)
2. @State、@Provide、 @Link和@Consume四种状态变量的数据类型声明只能由简单数据类型或引用数据类型的其中一种构成。 2. @State、@Provide、 @Link和@Consume四种状态变量的数据类型声明只能由简单数据类型或引用数据类型的其中一种构成。
类型定义中的Length、ResourceStr、ResourceColor三个类型是简单数据类型或引用数据类型的组合,所以不能被以上四种状态装饰器变量使用。 类型定义中的Length、ResourceStr、ResourceColor三个类型是简单数据类型或引用数据类型的组合,所以不能被以上四种状态装饰器变量使用。
...@@ -76,18 +55,14 @@ ...@@ -76,18 +55,14 @@
**变更影响** **变更影响**
1. 如果状态装饰器变量没有显式声明变量类型,声明any,编译拦截报错 1. 如果状态装饰器变量没有显式声明变量类型,声明any,编译拦截会出现警告
```ts ```ts
// ArkTS:ERROR Please define an explicit type, not any. // ArkTS:WARN Please define an explicit type, not any.
@State isLunar: any = false @State isLunar: any = false
``` ```
2. 状态装饰器变量声明变量类型为Date,编译拦截报错;
```ts
// ArkTS:ERROR The @State property 'selectedDate' cannot be a 'Date' object.
@State selectedDate: Date = new Date('2021-08-08')
```
3. @State、@Provide、 @Link和@Consume四种状态变量使用框架提供的Length、ResourceStr、ResourceColor, 3. @State、@Provide、 @Link和@Consume四种状态变量使用框架提供的Length、ResourceStr、ResourceColor,
编译拦截报错。 编译拦截报错。
```ts ```ts
/* ArkTS:ERROR The state variable type here is 'ResourceStr', it contains both a simple type and an object type, /* ArkTS:ERROR The state variable type here is 'ResourceStr', it contains both a simple type and an object type,
which are not allowed to be defined for state variable of a struct.*/ which are not allowed to be defined for state variable of a struct.*/
...@@ -101,9 +76,8 @@ ...@@ -101,9 +76,8 @@
**适配指导** **适配指导**
1. 状态装饰器变量声明具体的变量类型替代any; 1. 状态装饰器变量声明具体的变量类型替代any;
2. 使用Date对象的状态装饰器变量,修改为不加状态装饰器修饰的常规变量;
3. 因为Length(string|number|Resource), ResourceStr(string|Resource), ResourceColor(string|number|Color|Resource) 3. 因为Length(string|number|Resource), ResourceStr(string|Resource), ResourceColor(string|number|Color|Resource)
的三个类型是简单数据类型或引用数据类型的组合,使用@State、@Provide、 @Link和@Consume四种状态变量场景参考以下修改: 的三个类型是简单数据类型或引用数据类型的组合,使用@State、@Provide、 @Link和@Consume四种状态变量场景参考以下修改:
```ts ```ts
// 错误写法: // 错误写法:
@State message: ResourceStr = $r('app.string.hello') @State message: ResourceStr = $r('app.string.hello')
...@@ -144,7 +118,7 @@ ...@@ -144,7 +118,7 @@
**变更影响** **变更影响**
1. 不允许从父组件初始化`@LocalStorageLink`, `@LocalStorageProp`修饰的变量。 1. 不允许从父组件初始化`@LocalStorageLink`, `@LocalStorageProp`修饰的变量,编译出现警告
```ts ```ts
@Entry @Entry
@Component @Component
...@@ -152,10 +126,10 @@ ...@@ -152,10 +126,10 @@
build() { build() {
Column() { Column() {
Child({ Child({
/* ArkTS:ERROR Property 'simpleVarName' in the custom component 'Child' cannot /* ArkTS:WARN Property 'simpleVarName' in the custom component 'Child' cannot
initialize here (forbidden to specify). */ initialize here (forbidden to specify). */
simpleVarName: 1, simpleVarName: 1,
/* ArkTS:ERROR Property 'objectName' in the custom component 'Child' cannot /* ArkTS:WARN Property 'objectName' in the custom component 'Child' cannot
initialize here (forbidden to specify). */ initialize here (forbidden to specify). */
objectName: new ClassA("x") objectName: new ClassA("x")
}) })
...@@ -211,7 +185,7 @@ ...@@ -211,7 +185,7 @@
**适配指导** **适配指导**
1. 构造子组件时,不对子组件的`@LocalStorageLink`, `@LocalStorageProp`修饰的变量进行。 1. 构造子组件时,不对子组件的`@LocalStorageLink`, `@LocalStorageProp`修饰的变量进行。
如果需要在父组件中修改子组件的`@LocalStorageLink`, `@LocalStorageProp`修饰的变量,则使用LocalStorage提供的API接口方法(比如set方法)赋值。 如果需要在父组件中修改子组件的`@LocalStorageLink`, `@LocalStorageProp`修饰的变量,则使用LocalStorage提供的API接口方法(比如set方法)赋值。
2. @ObjectLink的使用指导请参考文档[@ObjectLink使用指导](../../../application-dev/quick-start/arkts-observed-and-objectlink.md) 2. @ObjectLink的使用指导请参考文档[@ObjectLink使用指导](../../../application-dev/quick-start/arkts-observed-and-objectlink.md)
## cl.arkui.3 List组件和Scroll组件onScrollBegin事件变更 ## cl.arkui.3 List组件和Scroll组件onScrollBegin事件变更
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册