/** * ArkTS之循环渲染 */ @Component struct MyChild { label:string build() { Text(this.label) .fontSize(30) } } @Entry @Component struct MyParent { @State my_array: Array<string> = ['one','two','three','four','five'] build() { Column() { Button('点击修改第二个值') .fontSize(24) .fontColor(Color.Red) .onClick(()=>{ this.my_array[1] = 'new_two' }) Button('点击修改第三个值') .fontSize(24) .fontColor(Color.Red) .onClick(()=>{ this.my_array[2] = 'new_three' }) ForEach(this.my_array,(item:string, index:number)=>{ MyChild({label:item}) .margin({top:20}) }) } .justifyContent(FlexAlign.Center) .width('100%') .height('100%') } }
标签:ArkTS,渲染,label,案例,fontSize,array,my From: https://www.cnblogs.com/zhzhang/p/17969433