zoukankan      html  css  js  c++  java
  • vue超简选中行改变样式demo

    需求:

    点击某行,某行应用不同样式

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            .active {
                color: red;
            }
        </style>
    </head>
    <body>
        <div id="app">
            <ul>
                <li v-for = '(i,index) in movies'
                :class = '{active : currentIndex === index}'
                @click = 'btn(index)'
                >{{i}}</li>
                <!-- 把currentindex 和index对比,相同的设置样式 -->
            </ul>
        </div>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
        <script>
            const app = new Vue({
                el : '#app',
                data : {
                    movies : ['movie1','movie2','movie3','movie4'],
                    currentIndex : 2,
                    //当前选择是哪一个
                },
                methods :{
                    btn(index) {
                        this.currentIndex = index;
                    }
                }
            })
        </script>
    </body>
    </html>
  • 相关阅读:
    中国象棋评估函数建模
    C语言中指针变量传参
    STM32外部中断
    C语言中的注释
    STM32学习网址
    C语言中的布尔值
    更改KEIL背景配色
    Modbus通讯协议
    DUP
    算法的时间复杂度
  • 原文地址:https://www.cnblogs.com/sandraryan/p/13879931.html
Copyright © 2011-2022 走看看