vue实现tab切换

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            *{
                margin: 0;
                padding: 0;
            }
            ul{
                width:100%;
                background-color: yellow;
                margin-bottom: 20px !important;
            }
            li{
                list-style: none;
                display: inline-block;                
                background-color: yellowgreen;
                cursor: pointer;
                margin-right: 20px;
                        
            }
            li a{
                padding: 10px 30px;
                display: inline-block;
            }
            .bg-red{
                background-color: red;
            }
            .bg-lime{
                background-color: lime;
            }
            .bg-pink{
                background-color: pink;
            }
            .bg-green{
                background-color: green;
            }
            .scWrap{
                width: 100%;
                
                position: relative;
                margin-top: 50px;
            }
            .sc{
                width: 100%;
                height: 300px;
                position: absolute;
            }
            .active{
                background-color: blue;
                color: white;
            }
            .dp{
                display: block;
            }
            .non{
                display: none;
            }
            [v-cloak]{
                display: none;
            }
        </style>
    </head>
    <body>
        <div class="app" v-cloak>
            <ul>
                <li v-for="(item,index) in list0">
                    <a @click="changeBox(index)" :class="{active:currentN==index}">{{item.ct}}</a>                    
                </li>

            </ul>
            <!--[msg,m]-->
            <section id="scWrap">
                <div v-for="(item,index) in list"  v-show="index==currentN" :class="[item.bg,sc]">{{item.content}}</div>                
            </section>
        </div>
        
        
        
        
        
        <script src="vue.js"></script>
        <script>
            new Vue({
                el:'.app',
                data:{
                    currentN:0,
                    sc:'sc',
                    
                    list0:[
                        {
                            ct:'btn11'
                        },
                        {
                            ct:'btn22'
                        },
                        {
                            ct:'btn33'
                        },
                        {
                            ct:'btn44'
                        }
                    ],
                    list:[
                        {
                            bg:'bg-red',
                            content:'box01'
                        },
                        {
                            bg:'bg-lime',
                            content:'box02'
                        },
                        {
                            bg:'bg-pink',
                            content:'box03'
                        },
                        {
                            bg:'bg-green',
                            content:'box04'
                        }
                    ]
                },
                methods:{
                    changeBox(idx){
                        this.currentN=idx;
                    }
                }
            })
        </script>
    </body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值