vuedemo07

作者: 知识分享share | 来源:发表于2018-03-30 10:43 被阅读0次
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
    <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="app">
            <h1 v-bind:class="{red:false}">动态css class</h1>
            <h2>示例 1</h2>
            <!--<div v-on:click="changeColor=!changeColor" v-bind:class="{changeColor:changeColor}">
                <span>hery</span>
            </div>-->
            <h2>示例 2</h2>
            <button v-on:click="changeColor=!changeColor">change color</button>
            <button v-on:click="changeLength=!changeLength">change length</button>
            <div v-bind:class="compClasses"><span>
            hery</span></div>
            
        </div>
    </body>
</html>
<script>
    new Vue({
        el:"#app",
        data:{
            changeColor:false,
            changeLength:false
        },
        methods:{},
        computed:{
            compClasses:function(){
                return {
                    changeColor:this.changeColor,
                    changeLength:this.changeLength
                }
            }
        }
    });
</script>

相关文章

网友评论

      本文标题:vuedemo07

      本文链接:https://www.haomeiwen.com/subject/ihwbcftx.html