Vue的Class和Style的数组与集合

代码注释清清楚楚,这里不多做解释了,只需引用vue的js即可

一、vue代码:

<!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>

    <script src="js/vue.js" type="text/javascript"></script>

    <style type="text/css">    

    .active{

        border: 5px solid yellow;

        width: 200px;

        height: 200px;

    }

    .error{

        background-color: aqua;

    }

</style>


 

</head>

<body>

    <div id="zpy">

        <!--class对象语法测试-->

        <div v-bind:class="{active:isactive,error:iserror}">

            class对象语法测试

        </div>

        <button @click="handle1">换回原来样式</button>

    

        <!--class数组语法测试-->

        <div v-bind:class="[activeClass,errorClass]">

            class数组语法测试

        </div>

        <button @click="handle2">换回原来样式</button>

    

        <!--style对象语法测试,有两种方法-->

        <!--方法一-->

        <div v-bind:style="{color:'red',border:'5px solid green',width:'200px',height:'200px'}">

            style对象语法测试1

        </div>

        <button @click="handle3">换回原来样式</button>

        

        <!--方法二-->

        <div v-bind:style="{color:styleColor,border:styleBorder}">

            style对象语法测试2

        </div>

        <button @click="handle3">换回原来样式</button>

        <!--style数组语法测试-->

        <div v-bind:style="[styleWidth,styleHeight]">

            style数组语法测试

        </div>

        <button @click="handle4">换回原来样式</button>

    </div>


 

    <script type="text/javascript">

    new Vue({

        el:"#zpy",

        data:{

            isactive:true,

            iserror:true,

            activeClass:"active",

            errorClass:"error",

            styleColor:'black',

            styleBorder:'10px solid orange',

            styleWidth:{

                width:'400px',

                border:'5px solid red',

            },

            styleHeight:{

                height:'200px',

                backgroundColor:'pink',

            }

        },

        methods: {

            handle1:function(){

                this.isactive=!this.isactive;

                this.iserror=!this.iserror;

            },

            handle2:function(){

                // this.errorClass=!this.errorClass;

                this.errorClass="";

            },

            handle3:function(){

              

            },

            handle4:function(){

                this.styleHeight.backgroundColor="";

            }

        },

    })

    </script>

</body>

</html>

二、浏览器的页面效果图

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值