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>

 

posted @ 2021-01-23 17:41  King-DA  阅读(419)  评论(0编辑  收藏  举报