<!-- 点击添加字体颜色 -->
    <style scoped>
        .active {
            color: red;
        }
    </style>
    <div id="app-2">
        <ul>
            <li v-for="(item,index) in movies" :class="{active:index == isSelect}" @click="bindColor(index)">
                {{index}}:{{item}}</li>
        </ul>
    </div>
    <script>
        new Vue({
            el: "#app-2",
            data: {
                isSelect: false,
                color: 'red',
                movies: ['海贼王', '火影', '死神', '天空之城',]
            },
            methods: {
                bindColor: function (index) {
                    console.log(index)
                    this.isSelect = index
                }
            }
        })
    </script>
Logo

前往低代码交流专区

更多推荐