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

!8717 @state复合类型声明规则修改

Merge pull request !8717 from Bo Jiang/master
......@@ -40,7 +40,7 @@ struct MyComponent {
### 支持的装饰器列表
| 装饰器 | 装饰内容 | 说明 |
| ------------- | ---------------------------------------- | ---------------------------------------- |
| ------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| @Component | struct | 结构体在装饰后具有基于组件的能力,需要实现build方法来更新UI。 |
| @Entry | struct | 组件被装饰后作为页面的入口,页面加载时将被渲染显示。 |
| @Preview | struct | 用@Preview装饰的自定义组件可以在DevEco Studio的预览器上进行预览,加载页面时,将创建并呈现@Preview装饰的自定义组件。 |
......@@ -167,3 +167,31 @@ 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.
先完成此消息的编辑!
想要评论请 注册