前端-vue基础19-样式绑定2

<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .active {
            width: 100px;
            height: 100px;
            border: 1px solid red;
        }
        
        .error {
            background-color: orange;
        }
    </style>
</head>
 
<body>
    <div id="app">
        <div v-bind:class="[activeClass,errorClass]">
            我是歌谣
        </div>
        <button v-on:click="handle">切换</button>
    </div>
    <script type="text/javascript" src="./js/vue.js"></script>
    <script>
        /* 样式绑定 */
        var vm = new Vue({
            //绑定的标签
            el: '#app',
            //自定义按键修饰符
            data: {
                activeClass: 'active',
                errorClass: 'error'
            },
            methods: {
                handle: function() {
                    //控制isactive奇幻
                    this.activeClass = '';
                    this.errorClass = '';
                }
            }
        });
    </script>
</body>
 
</html>

 

posted @ 2022-07-23 22:30  前端导师歌谣  阅读(26)  评论(0)    收藏  举报