Vue2-案例tab切换栏高亮

 思路:

  1. 基于数据的动态渲染tab --v-for
  2. 准备下标记录哪个是高亮tab--activeIndex
  3. 基于下标,动态控制class的类名--v-bind:class OR :class

高亮其实就是更改下标

<!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>
        ul {
            width: 100%;
            height: 55px;
            border-bottom: 1px solid red;
        }

        li{
            list-style: none;
            line-height: 55px;
            text-align: center;
            width: 120px;
            height: 55px;
            float: left;
            font-size: 25px;
            margin-right: 10px;
           
        }

        a {
            text-decoration: none;
            color: black;

        }
        .active {
            display: inline-block;
            width: 120px;
            height: 55px;
            background-color: orangered;
            color: #fff;
        }
    </style>
</head>

<body>

    <div id="app">
        <ul>
            <li v-for="(item,index) in list" :key="item.id" @click="activeIndex = index">
                <a :class="{active: index === activeIndex}" href="#">{{item.name}}</a>
            </li>
        </ul>
    </div>

    <!-- 引入是开发版本的包 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script>


    <script>
        const app = new Vue({
            el: '#app',
            data: {
                activeIndex: 0,//高亮显示
                list: [{ id: 1, name: '淘宝特卖' },
                { id: 2, name: '京东特卖' },
                { id: 3, name: '百度特卖' },
                { id: 4, name: '平刀特卖' },
                ]
            },
            methods: {

            },
        })
    </script>
</body>

</html>

相关推荐

  1. Vue2-案例tab切换

    2024-07-15 07:38:02       26 阅读
  2. tab分页切换tab交互

    2024-07-15 07:38:02       54 阅读
  3. js实现tab切换

    2024-07-15 07:38:02       52 阅读
  4. tab切换 vue

    2024-07-15 07:38:02       30 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-15 07:38:02       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-15 07:38:02       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-15 07:38:02       58 阅读
  4. Python语言-面向对象

    2024-07-15 07:38:02       69 阅读

热门阅读

  1. 项目管理·沟通管理

    2024-07-15 07:38:02       26 阅读
  2. CentOS Stream 卸载 Podman 并安装 Docker 的方法

    2024-07-15 07:38:02       22 阅读
  3. 关于 LayoutInflater.inflate 的取值结论

    2024-07-15 07:38:02       22 阅读
  4. Zynq7000系列FPGA中的DMA控制器的编程限制

    2024-07-15 07:38:02       20 阅读
  5. [Spring Boot]定时任务因系统时间修改之后无法执行

    2024-07-15 07:38:02       20 阅读
  6. Redis避坑疑难杂症

    2024-07-15 07:38:02       20 阅读