class动态样式

  • :class=“变量”
  • :class=“三元运算符”
  • :class=“{类名1:ture,类名2:false,类名3:false}”
  • 当样式超过2个以上显示时,需要使用{},类名的值为true时,样式显示,为false时隐藏
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 1.引入vue.js -->
    <script src="./vue.js"></script>
    <style>
        .red{
            background: red;
        }
        .lime{
            color: lime;
        }
        .blue{
            background: blue;
        }
        .grey{
            background: grey;
        }
    </style>
</head>
<body>
    <!-- 2.作用域 -->
    <div id="app">
        <!-- 动态样式1:   :class="变量" -->
        <h1 :class="classN">蒹葭苍苍</h1>
        <button @click="changeBlue()">变蓝</button>
        <button @click="changeGrey()">变灰</button>
        <hr>
        <!-- 动态样式2 :class="三元运算符" -->
        <h2 :class="isShow ? 'blue lime' : 'grey lime'">白露为霜</h2>
        <ul>
            <li v-for="(item,index) of arr" :class="index%2==0 ? 'blue lime' : 'grey lime'">{{item}}</li>
        </ul>
        <hr>
        <!-- 动态样式3 :class="{类名1:ture,类名2:false,类名3:false}"-->
        <div :class="{red:false,blue:true,lime:true}">小荷才露尖尖角</div>
        <ul>
            <li v-for="(item,index) in arr" :class="{red:index%3===0,grey:index%3===1,blue:index%3===2}">
                {{item}}
            </li>
        </ul>
    </div>
    <script>
        // 3.实例化vue
        new Vue({
            el:'#app',
            // 数据
            data:{
                classN:'red lime',
                isShow:true,
                arr:['科比','詹姆斯','乔丹','姚明','易建联','刘劲']
            },
            // 方法
            methods:{
                changeBlue(){
                    this.classN = 'blue lime';
                },
                changeGrey(){
                    this.classN = 'grey lime';
                }
            }
        })
    </script>
</body>
</html>
<el-button type="primary" style="width: 100%" @click="submit" :loading="isRequesting">
              {{ isRequesting ? '创建中' : '确定' }}
            </el-button>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值