请问大佬,为啥我模仿官方教程做@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%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.

点击后,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
6510浏览 • 1回复 待解决
HarmonyOS LazyForEach不会更新@State里的
530浏览 • 1回复 待解决
Map转JSON,哪位大佬知道怎么解决
2153浏览 • 0回复 待解决
HarmonyOS ArrayBuffer对象操作
352浏览 • 1回复 待解决
大佬告知如何修改项目包名?
896浏览 • 1回复 待解决
大佬告知如何获取设备的dpi
2199浏览 • 1回复 待解决
请问怎么MySQL的数据优化?
2732浏览 • 2回复 待解决
arkts父子组件组件怎么通信传
5959浏览 • 1回复 待解决
哪位Java大佬能告诉错在哪里?
2915浏览 • 0回复 待解决