码迷,mamicode.com
首页 > 其他好文 > 详细

vue动态绑定类(实现tab)

时间:2021-04-20 15:35:33      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:box   html   har   method   hit   port   white   spl   red   

<!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="https://cdn.jsdelivr.net/npm/vue"></script>
    <style>
        .box {
            color: rebeccapurple;
        }

        .box_width {
            width: 400px;
            height: 400px;
            background-color: red;
            border: 1px solid green;
        }

        .uli {
            display: flex;
            list-style: none;
        }

        .uli li {
            margin: 15px;
        }

        .uli li:hover {
            cursor: pointer;
        }

        .back {
            color: red;
            background-color: royalblue;
        }

        .backfalse {
            background-color: green;
            color: white;
        }
    </style>
</head>

<body>
    <div id="app">
        <div :class="bindClass">{{msg}}</div>
        <button @click="btn(‘add‘)">增加样式</button>
        <button @click="btn(‘cutback‘)">减少样式</button>
        <ul class="uli">
            <li v-for="(item,index) in arrs" :key="index" @click="ulBtn(index)"
                :class="[index==isBack?‘back‘:‘backfalse‘]">
                {{item}}
            </li>
        </ul>
    </div>
    <script>
        new Vue({
            el: "#app",
            data: {
                msg: "测试",
                bindClass: "",
                arrs: ["便签一", "便签二", "便签三"],
                isBack: 0,
            },
            methods: {
                btn(data) {
                    if (data == "add") {
                        this.bindClass = "box box_width";
                    } else {
                        this.bindClass = "";
                    }
                },
                ulBtn(e) {
                    this.isBack = e
                },
            },
        });
    </script>
</body>

</html>

 

vue动态绑定类(实现tab)

标签:box   html   har   method   hit   port   white   spl   red   

原文地址:https://www.cnblogs.com/lyt520/p/14674555.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!