请问大佬,为啥我模仿官方教程做@State后面的布尔值修改不了啊

@Entry
@Component
struct Index {
  @State message: string = 'Test'
  @State testColor : Boolean = true;
  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .fontColor(this.testColor ? Color.Blue : Color.Red)
      }
      .width('100%')
      .onClick(() => {
        this.testColor = !this.testColor;
        // this.message = '?';
        console.log(this.testColor ? 'true' : 'false');
      })
    }
    .height('100%')
  }
}

点击后,log显示testColor这个布尔值一直不变,我把@State去掉后倒是可以变,但是字体颜色不变,嘤嘤嘤

有哪位大佬能帮忙解释一下吗

DevEco Studio
UI
2023-10-23 15:22:46
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
Bowma

@State testColor : 

Boolean = true;

Boolean 改为 小写 boolean

分享
微博
QQ
微信
回复
2023-10-23 17:32:50
相关问题
手机应用,不了signing
4545浏览 • 1回复 待解决
想跟着APP,让老司机带带
7765浏览 • 6回复 待解决
大佬告知如何获取设备的dpi
820浏览 • 1回复 待解决
哪位Java大佬能告诉错在哪里?
1248浏览 • 0回复 待解决
arkts父子组件组件怎么通信传
3612浏览 • 1回复 待解决
请问怎么MySQL的数据优化?
1227浏览 • 2回复 待解决
上架版本pack.info里面Debug如何修改
516浏览 • 1回复 待解决