Vue 点击元素变色
Vue 点击元素变色
<style> .activeClass{ outline: 2px solid #c0c0c0; background-color: #c0c0c0; } </style> <div id="app"> <ul> <li v-for="(item,index) in classInfo" :class="{activeClass: isActive===index}" @click="isActive=index"> {{item.value}} </li> </ul> </div> <script src="vue.js"></script> <script type="module"> const app = new Vue({ el: '#app', data() { return { classInfo: [ {key:"1",value:"daFei"}, {key:"2",value:"foo"}, {key:"3",value:"bar"}, ], isActive: "", } } }); </script>