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

vue 点击当前元素添加class 去掉兄弟的class

时间:2019-08-19 19:04:01      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:ack   ext   set   选项   jquery   img   pat   method   sheet   

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>vue 点击当前元素添加class 去掉兄弟的class</title>
    <link rel="stylesheet" href="">
    <!--<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>-->
    <!--<script type="text/javascript" src="../js/jquery-2.1.4.min.js"></script>-->
    <script type="text/javascript" src="../js/vue.js"></script>
    <style type="text/css">
        .blue {color: #2175bc;}
    </style>
</head>
<div id="app">
    <ul>
        <li v-for="(todo, index) in todos" v-on:click="addClass(index)" v-bind:class="{ blue:index==current}">
            {{ todo.text }}
        </li>
    </ul>
</div>
<script>
    new Vue({
        el: #app,
        data: {
            current:0,
            todos: [
                { text: 选项一 },
                { text: 选项二 },
                { text: 选项三 }
            ]
        },
        methods:{
            addClass:function(index){
                this.current=index;
            }
        }
    })
</script>

</script>
</html>

技术图片

 

vue 点击当前元素添加class 去掉兄弟的class

标签:ack   ext   set   选项   jquery   img   pat   method   sheet   

原文地址:https://www.cnblogs.com/li-sir/p/11378702.html

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