时间:2021-07-04 09:25:50 | 栏目:vue | 点击:次
本文实例为大家分享了vue循环数组改变点击文字颜色的具体代码,供大家参考,具体内容如下
效果图 如下所示
<!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 id="app"> <ul> <li v-for="(item,index) in username" @click="bution(index)" :class="index == colin?'red':''">{{index}}.{{item}}</li> </ul> </div> <script src="../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>