cssjshtml vue.js 动态添加class

葫芦的运维日志

下一篇 搜索 上一篇

2019/01/02 15:14


<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>methods_and_computed</title>
    <style>
        span {
            background: red;
            display: inline-block;
            padding: 10px;
            color: #fff;
            margin: 10px 0;
        }

        .changeColor span {
            background: green;
        }

        .changeLength span:after {
            content: "length";
            margin-left: 10px;
        }
    </style>
</head>
<body>
<div id="vue-app">
    <h1> 动态 CSS Class </h1>
    <h2> 示例 </h2>
    <button v-on:click="changeColor=!changeColor">changeColor</button>
    <button v-on:click="changeLength=!changeLength">changeLength</button>
    <div v-bind:class="compClasses">
        <span>Brownwang</span>
    </div>
</div>

<script src="/static/js/vue.min.js"></script>
<script>
    new Vue({
        el: "#vue-app",
        data: {
            changeColor: false,
            changeLength: false
        },
        methods: {},
        computed: {
            compClasses: function () {
                return {
                    changeColor: this.changeColor,
                    changeLength: this.changeLength
                }
            }

        }


    });
</script>
</body>
</html>

 

 

葫芦的运维日志

打赏

上一篇 搜索 下一篇
© 冰糖葫芦甜(bthlt.com) 2019 王梓 打赏联系方式 陕ICP备17005322号