vue中class样式的设置

<!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>
    <script src="vue.js"></script>
    <style>
        .red{
            color: red;
        }
        .thin{
            font-weight: 200
        }
        .italic{
            font-style: italic
        }
        .active{
            letter-spacing: 0.5em
        }
    </style>
</head>
<body>
    <div id="app">
        <h1 class="red thin">{{msg}}</h1>
        <!-- 普通使用 -->
        <h1 :class="['red','thin']">{{msg}}</h1>
        <!--三元表达式-->
        <h1 :class="['red','thin',flag?'active':'']">{{msg}}</h1>
        <!--使用对象-->
        <h1 :class="['red','thin',{'active':flag}]">{{msg}}</h1>

        <h1 :class="classObj">{{msg}}</h1>
    </div>
</body>
<script>
    //创建一个vue实例
    //当我们导入包之后,在浏览器的内存中就多了一个vue构造函数
    var vm = new Vue({
        el: '#app',//表示当前我们new的这个vue实例要控制页面上的哪个区域
        data: { //data属性中存放的是el中要用到的数据
            msg: '我是你爸爸',
            flag: true,
            classObj: {red: true,thin: true,italic: true,active: true}
        }
    });
</script>
</html>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章