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



<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; } } })


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM