首页 > 其他 > 详细

【VUE】点击列表某一项,该项文字变成红色(currentIndex: 0经常用)

时间:2021-04-14 23:27:39      阅读:21      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!-- 动态类class,布尔值是index是否相同;@click作用是index赋值 -->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <!-- 官方axios在线地址 -->
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <!-- <script src="vue.js"></script> -->
    <style>
        .isred {
            color: red;
        }
    </style>
</head>

<body>
    <div id="app">
        <ul>
            <li v-for="(item,index) in arr" :class="{isred:currentIndex===index}" @click="change(index)">{{item}}</li>
        </ul>
    </div>

    <script>
        var area = new Vue({
            el: "#app",
            data: {
                arr: ["还望", "海尔兄弟", "火影忍者"],
                currentIndex: 0
            },
            methods: {
                change: function(index) {
                    this.currentIndex = index;
                }
            }
        });
    </script>
</body>

</html>

【VUE】点击列表某一项,该项文字变成红色(currentIndex: 0经常用)

原文:https://www.cnblogs.com/icemiaomiao3/p/14659832.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!