首页 > 其他 > 详细

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

时间:2019-01-12 10:21:48      阅读:200      评论:0      收藏:0      [点我收藏+]
<!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>

效果:

技术分享图片

演示地址:
https://xibushijie.github.io/static/addClass.html

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

原文:https://www.cnblogs.com/haima/p/10258552.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!