未验证 提交 9ade866d 编写于 作者: B Bo Jiang 提交者: Gitee

update zh-cn/application-dev/ui/ts-syntactic-sugar.md.

Signed-off-by: NBo Jiang <jiangbo91@huawei.com>
上级 c60e6d33
......@@ -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.
先完成此消息的编辑!
想要评论请 注册