<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .active {
            border:1px solid red;
            width:100px;
            height:100px;
        }
        .error {
            background-color: orange;
        }
    </style>
</head>
<body>
    <div id = "app1">
        <div>
            <div v-bind:class="{active:isActive,error:isError}">测试样例</div>
            <button v-on:click="handle">切换</button>
        </div>
    </div>
    <script src="vue.js"></script>
    <script>
        var vue1 = new Vue({
            el: '#app1',
            data:{
                isActive:true,
                isError:true
            },
            methods:{
                handle:function(){
                    this.isActive = !this.isActive;
                    this.isError = !this.isError;
                }
            }
        })
    </script>
</body>
</html>

以上是class样式绑定

posted on 2020-08-01 17:34  知否知否,  阅读(78)  评论(0编辑  收藏  举报