基于Vue的Tab选项卡

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style type="text/css">
        .tab ul {
            overflow: hidden;
            padding: 0;
            margin: 0;
        }
        .tab ul li {
            box-sizing: border-box;
            padding: 0;
            float: left;
            width: 200px;
            height: 60px;
            line-height: 45px;
            list-style: none;
            text-align: center;
            border-top: 1px solid blue;
            border-right: 1px solid blue;
            cursor: pointer;
        }
        .tab ul li:first-child{
            border-left: 1px solid blue;
        }
        .tab ul li.active{
            background-color: red;
        }
        .tab div{
            width: 598px;
            height: 400px;
            display: none;
            text-align: center;
            font-size: 30px;
            line-height: 300px;
            border: 1px solid blue;
            border-top: 0px;
        }
        .tab div.current{
            display: block;
        }
        .tab img{
            width: 598px;
            height: 400px;
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="tab">
            <ul>
                <li v-on:click='change(index)' :class='currentIndex==index?"active":""' :key='item.id' v-for='(item,index) in list'>{{item.title}}</li>
            </ul>
            <div :class='currentIndex==index?"current":""' :key='item.id' v-for='(item,index) in list'>
                <img :src="item.path">
            </div>
        </div>
    </div>
    <script type="text/javascript" src="vue.js"></script>
    <script type="text/javascript">
        var vm = new Vue({
            el:'#app',
            data:{
                currentIndex:0, //选项卡当前的索引 
                list:[{
                    id:1,
                    title:'apple',
                    path:'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fbaidu-mip.xianjichina.com%2Fdata%2Fediter%2F20170316%2Fimage%2F20c072806d15bd65ea34b00d0fc8f4e9.jpg&refer=http%3A%2F%2Fbaidu-mip.xianjichina.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1628328239&t=bb33bff7b02cc5dd45c59dc079032e45',
                },{
                    id:2,
                    title:'orange',
                    path:'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fhgdy.vip%2Fd%2Ffile%2F20171227%2F2017122761396297.jpg&refer=http%3A%2F%2Fhgdy.vip&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1628328280&t=b49783cc51b2ecc98efb2f3cee72cc59',
                },{
                    id:3,
                    title:'lemon',
                    path:'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.jdgfgyt.com%2Fuploadfile%2F2020%2F0304%2F20200304041448778.jpg&refer=http%3A%2F%2Fwww.jdgfgyt.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1628328310&t=0d5ed8776caca1a705869c7bd8a94c7b',
                }]
            },
            methods:{
                change:function(index){
                    // 在这里实现选项卡切换操作: 本质就是操作类名
                    // 就是通过currentIndex
                    this.currentIndex = index;
                }
            },
        })
    
    </script>
</body>
</html>

 基于Vue的Tab选项卡

 

基于Vue的Tab选项卡

 基于Vue的Tab选项卡

 

上一篇:第一次上坟


下一篇:WPF 框架全构建环境虚拟机硬盘分享