基础使用
无构造参数配置
例如,以下Divider组件不包含构造参数:
Column() { Text('item 1') Divider() // No parameter configuration of the divider component Text('item 2') }
必选参数构造配置
Image('http://xyz/a.jpg')
Text组件的必选参数content:
Text('123')
变量或表达式也可以用于参数赋值,其中表达式返回的结果类型必须满足参数类型要求。
传递变量或表达式来构造Image和Text组件的参数示例
// imagePath, where imageUrl is a private data variable defined in the component. Image(this.imagePath) Image('http://' + this.imageUrl) // count is a private data variable defined in the component. // (``) and (${}) are the template character string features supported by the TS language and comply with the // features of the corresponding language. This specification is not limited. Text(`count: ${this.count}`)
属性配置
使用属性方法配置组件的属性。属性方法紧随组件,并用“.”运算符连接。
配置Text组件的字体大小属性示例:
Text('123') .fontSize(12)