鸿蒙子组件根据数据,刷新item Ui的规范
鸿蒙
子组件列表中,有多个isSelect,父组件只用一个@state类型的isSelect,就可以将它们关联起来,如下:
isLike:item1.isPraise?!this.isLike:this.isLike,
子组件想要数据变化,UI随着更新,就得让父组件的@state关联,只要1个变量就可以。
父组件中:
@Prop isFinished: boolean;
@Prop things: string;
List() {
ForEach(this.data.planList, (item: string) => {
// 待办事项1
ThingsComponent({isFinished: this.isFinished, things: item})
.margin(5)
})
}
子组件中:
@Component
export struct ThingsComponent{
@Prop isFinished: boolean;
@Prop things: string;
Text(`${this.things}`)
.fontSize(24)
.fontWeight(450)
.decoration({type: this.isFinished ? TextDecorationType.LineThrough : TextDecorationType.None})
.onClick(() => {
this.things += '啦';
})
}