效果图 如下所示
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> *{ list-style: none; margin: 0; padding: 0; } .red{ color: red; } </style> </head> <body> <div> <ul> <li v-for="(item,index) in username" @click="bution(index)" :class="index == colin?'red':''">{{index}}.{{item}}</li> </ul> </div> <script src="https://www.jb51.net/js/vue.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> const obj = { username:['张三','李四','王五','二麻子'], colin:-1, } const app = new Vue({ el:'#app', data:obj, methods:{ bution:function(e){ this.colin = e } } }) </script> </body> </html>