“434f7dc585852443fd97097e3279e5fd7922c906”上不存在“src/views/tool/git@gitcode.net:kinghzking/1024opensource.git”
未验证 提交 6aaed918 编写于 作者: O openharmony_ci 提交者: Gitee

!8766 状态变量多种类型声明限制说明

Merge pull request !8766 from Bo Jiang/OpenHarmony-3.1-Release
......@@ -166,3 +166,32 @@ struct bindPopup {
}
}
```
## 状态变量多种数据类型声明使用限制
@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%')
}
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册