zoukankan      html  css  js  c++  java
  • vue动态绑定class和style

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            .aClass {
                color: red;
            }
    
            .bClass {
                color: blue;
            }
    
            .cClass {
                font-size: 30px;
            }
        </style>
    </head>
    
    <body>
    <div id="demo">
        <h2>1. class样式的绑定,使用套路: :class='xxx' </h2>
        <p :class="a">xxx是字符串</p>
        <!--:class属性值是对象时,key是class类名,value是true的,样式会生效-->
        <p :class="{aClass:isA, bClass:isB}">xxx是对象</p>
        <!--:class的值是数组,元素是class类名-->
        <p :class="['aClass','cClass']">xxx是数组</p>
    
        <h2>1. style样式的绑定,使用套路: :style='' </h2>
        <p :style="{color:activeColor,fontSize:fontSize+'px'}">style样式的绑定:xxx是对象</p>
    
    
        <button @click="update">更新</button>
    </div>
    <script type="text/javascript" src="lib/vue.min.js"></script>
    <script type="text/javascript">
        new Vue({
            el: "#demo",
    
            data: {
                a: 'aClass',
                b: 'bClass',
                isA: true,
                isB: false,
                activeColor:'green',
                fontSize:50
            },
            methods: {
                update(){
                    this.a = this.b;
                    this.isA = false;
                    this.isB = true;
                    this.activeColor = 'blue';
                    this.fontSize = 20;
                }
            }
        });
    </script>
    </body>
    </html>
    

    OK!

  • 相关阅读:
    linux设置永久别名
    网站架构
    c#: 判断Firefox是否安装
    似是故人来
    Python: re.sub()第二个参数
    Python: AES加密与解密
    c#: Noto Sans字体如何支持韩文
    Inno Setup安装程序单例运行
    朵朵的二维码
    Python: 浅淡Python中的属性(property)
  • 原文地址:https://www.cnblogs.com/z-qinfeng/p/12389532.html
Copyright © 2011-2022 走看看