08-鸿蒙4.0学习之If、else条件判断语句
08-鸿蒙4.0学习之If、else条件判断语句
代码
@Entry
@Component
struct Branch {
@State isShow: boolean = false
build() {
Row() {
Column() {
Button('切换')
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
this.isShow = !this.isShow
})
Text(this.isShow ? '显示' : '不显示')
if(this.isShow){
Branch_Comp({content:'我是显示情况下的子组件'})
}else{
Branch_Comp({content:'我是不显示情况下的子组件'})
}
}
.width('100%')
}
.height('100%')
}
}
@Component
struct Branch_Comp {
content: string = '自有'
build() {
Column() {
Text(this.content)
}
}
}
// 作业:写个逢七过的游戏