HarmonyOS 用calc设置宽度.width(calc(100% -30)),根据需要设置的margin做动态赋值

calc使用报错:

@Builder  
choiceLoginDeviceItem(item:LoginDeviceModel): void {  
    Row() {  
      if (this.isSelect) {  
        Image(item.selectIcon)  
          .height(15)  
          .margin({right:5})  
      }  
      LoginDeviceItem({  
        loginDevice:item,  
        logOut:false  
      })  
        .width(calc(100% - 30 - (this.isSelect ? 20 : 0)))  
    }  
    .margin({  
      left:15,  
      right:15,  
      bottom:10  
    })  
    .onClick(()=>{  
      this.singleChoiceSelectStateModify(item)  
    })  
  }
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
HarmonyOS
2024-10-10 10:53:32
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

需要使用引号引起来:

.width(calc(100% - 30 - (this.isSelect ? 20 : 0)))
  • 1.

替换成:

.width(`calc(100% - ${30 + (this.isSelect ? 20 : 0)}vp )`)
  • 1.
分享
微博
QQ
微信
回复
2024-10-10 16:48:12


相关问题
HarmonyOS 宽度100% margin左右不生效
1123浏览 • 1回复 待解决
HarmonyOS 子控件设置宽度100%问题
975浏览 • 1回复 待解决
HarmonyOS 为什么calc不生效呢
868浏览 • 1回复 待解决
能否使用类似css里calc方法
1277浏览 • 1回复 待解决
HarmonyOS 关于动态设置组件宽度问题
1160浏览 • 1回复 待解决
HarmonyOS 设置margin无效
598浏览 • 1回复 待解决
list-item 根据boolean属性 动态设置class
5329浏览 • 1回复 待解决
HarmonyOS text组件不设置width
763浏览 • 1回复 待解决