小程序中style三元表达式中需要绑定多个数据时解决方案

小程序中想要使用windowHeight需要在当前元素中添加style='height:"{{windowHeight}}"px;'

但不同情况下使用三元表达式改变高度时写成

<scroll-view scroll-y style='{{isHaveVideo ? "height:{{haveVideoHeight}}px" : "height:{{windowHeight}}px"}}'></scroll-view>

代码读到{{isHaveVideo ? “height:{{haveVideoHeight}}就会停止,所以更改为

<scroll-view scroll-y style='{{"height: " + (isHaveVideo ? haveVideoHeight : windowHeight) + "px;"}}'></scroll-view>

数据绑定的{{ }}只需要写在最外面即可

关于获取屏幕高度的方法可以看我的另一篇文章哦

https://blog.csdn.net/qq_41619741/article/details/89213456

猜你喜欢

转载自blog.csdn.net/qq_41619741/article/details/89212795