01_vue中的class案例

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>todos</title>
    <script src="https://cdn.bootcss.com/vue/2.4.2/vue.js"></script>
    <style>
        .box {
            width: 100px;
            height: 100px;
            border: 10px solid #ccc;
        }
        .active {
            background: red
        }
    </style>
</head>
<body>
    <div class="wrap" id="todos">
        <div class="box" :class='{active:isActive}' @click='setBG'>

        </div>
    </div>
</body>
<script>
    var todos = new Vue({
        el: '#todos',
        data: {
            isActive: false
        },
        methods: {
            setBG() {
                this.isActive = !this.isActive
                console.log(this.isActive)
            }
        }
    });
</script>
</html>
  this.isActive = !this.isActive   //主要是运用到这个取反,用途点击收藏时不同的效果
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容