(精华2020年5月4日更新) vue教程篇 class和style的使用

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>class和style</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style>
        .aa {
            color: red;
            font-size: 30px;
        }

        .bb {
            background-color: #ccc;
        }
    </style>
</head>

<body>
    <div id="itapp">
        <!-- class方式1: 变量的形式 -->
        <p :class="bb">class方式一</p> <!-- 不可以,Vue的属性绑定时不能直接css样式 -->

        <!-- class方式2:数组的形式 -->
        <p :class="[bb,dd]">class方式二</p>

        <!-- class方式3JSON  常用-->
        <p :class="{aa:true,bb:true}">class方式三(1</p>

        <p :class="{aa:num>2}">class方式三(2</p>
        <!-- style方式1JSON  常用-->
        <p style="color:red;font-size:40px">style方式一</p>
        <!-- v-bind:style -->
        <p :style="[xx,yy]">style方式二</p>
    </div>
    <script>
        new Vue({
            el: '#itapp',
            data: {
                bb: 'aa',
                dd: 'bb',
                num: 1,
                xx: {
                    color: 'blue',
                    fontSize: '30px'
                },
                yy: {
                    backgroundColor: '#ff7300'
                }
            }
        })
    </script>

</body>

</html>

你可能感兴趣的:((持续更新)vue基础篇)