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> <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>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/78f0e13be5523cf0e13f8b1a9ea5e368.html