为何我在uni-app的三元运算不起效果?


为何我在uni-app的三元运算不起效果?

    <view style="(item.l11_30=='true' ? 'background-color:red' : 'background-color:green')">
    
        </view>

<script>
    
    export default {
        data(){
        
        return{
        bga:'#CCCCCC',
        bgb:'#FFB9DC',
        ac:'true',
        a2:[],
        }

        },

        onShow: function() {
            
            //开始请求服务器数据开始
            uni.request({
                url:'http://localhost/app/1.asp',
                data: {
                    id1:'2',
                    id2:'addoil',
                    },
method: 'post',
                    header: {
                           'content-type': 'application/x-www-form-urlencoded',
                          },
                    success: (res) => {
                        console.log(res);

this.a2 = res.data;
    console.log(this.a2);
    
                    }
            });
            
            //开始请求服务器数据结束
        }
    
    }
    
</script>

直接写style只会识别为文字,必须使用动态样式:style才能识别变量和方法
如::style="{'margin-right': 1== 1 ? '32rpx' : ' ' }"

:style

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^