css:
<style type="text/css"> ul li {cursor: pointer;} .blue {color: #2175bc;} </style>
html:
<div id="app"> <ul> <li v-for="(todo, index) in todos" v-on:click="addClass(index,$event)" v-bind:class="{ blue:index==current}"> {{ todo.text }} </li> </ul> </div>
vue:
<script> new Vue({ el: '#app', data: { current:0, todos: [ { text: '选项一' }, { text: '选项二' }, { text: '选项三' } ] }, methods:{ addClass:function(index,event){ this.current=index; //获取点击对象 var el = event.currentTarget; alert("当前对象的内容:"+el.innerHTML); } } }) </script>
最后
以上就是洁净棉花糖最近收集整理的关于vue动态添加 li 被选样式css:html:vue:的全部内容,更多相关vue动态添加内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复