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="{box1:active}">1</div>
        <div v-bind:class="classgroup"></div>
    </div>
    <script>
        new Vue({
            el: "#app",
            data: {
                active: true,
                classgroup: { box: true, box1: true, box2: true }
            }
        })
    </script>
</body>

</html>