image.png

代码

 <!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue.js 样式-class 属性通过三目运算符绑定</title>
    <script src="//static.gzj2001.com/vue/vue.js"></script>
    <style>
       .box {
            background-color: springgreen;
        }

        .box1 {
            width: 250px;
            height: 250px;
        }

        .box3 {
            border: 1px solid rebeccapurple;
        }
    </style>
</head>
<body>
    <div id="app">
        <div v-bind:class="active?'box3':''">111</div>
    </div>
    <script>
        new Vue({
            el:"#app",
            data:{
                active:true,
            }
        })
    </script>
</body>
</html>