vue循环数组改变点击文字的颜色
人气:0效果图 如下所示
<!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>
您可能感兴趣的文章:
加载全部内容