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>

 

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