vue案例--选中变成红色
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> .active { color: red; } </style> </head> <body> <script src="../js/vue.js"></script> <div id="app"> <ui> <li v-for="(m,index) in movies" :class="{active:currentIndex===index}" @click="liClick(index)"> {{index}}.{{m}} </li> </ui> </div> <script> const app = new Vue({ el: '#app', data: { movies: ['海王', '海尔兄弟', '火影忍者', '进击的巨人'], currentIndex: 0 }, methods: { liClick(index){ this.currentIndex=index } } }) </script> </body> </html>
本文来自博客园,作者:King-DA,转载请注明原文链接:https://www.cnblogs.com/qingmuchuanqi48/p/14318378.html