From 9ade866de8d8c5cbb86b2a1433341b25bb5bac65 Mon Sep 17 00:00:00 2001 From: Bo Jiang Date: Fri, 26 Aug 2022 11:22:12 +0000 Subject: [PATCH] update zh-cn/application-dev/ui/ts-syntactic-sugar.md. Signed-off-by: Bo Jiang --- .../application-dev/ui/ts-syntactic-sugar.md | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/zh-cn/application-dev/ui/ts-syntactic-sugar.md b/zh-cn/application-dev/ui/ts-syntactic-sugar.md index 92b9df0a89..ec2ef4563f 100644 --- a/zh-cn/application-dev/ui/ts-syntactic-sugar.md +++ b/zh-cn/application-dev/ui/ts-syntactic-sugar.md @@ -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%') + } +} +``` + -- GitLab