未验证 提交 8a209fb9 编写于 作者: O openharmony_ci 提交者: Gitee

!10859 Added restrictions on the use of status variables.

Merge pull request !10859 from lihong/OpenHarmony-3.1-Release
...@@ -18,4 +18,39 @@ ...@@ -18,4 +18,39 @@
**关键的接口/组件变更** **关键的接口/组件变更**
\ No newline at end of file
### 状态变量多种数据类型声明使用限制。
状态变量比如@State、@Provide、 @Link和@Consume等,定义数据类型时,只能同时由简单数据类型或对象引用数据类型其中一种构成。
示例:
```ts
@Entry
@Component
struct Index {
//错误写法: @State message: string | Resource = 'Hello World'
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(`${ this.message }`)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
```
**变更影响**
当定义的状态变量类型中同时包含简单类型和对象引用数据类型时,编译报错提示不支持。
**关键的接口/组件变更**
当定义的状态变量类型中同时包含简单类型和对象引用数据类型时,需修改为只含有其中一种,如上述示例代码所示。
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册