Vue实现简单tab栏切换

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    .tab{
        width: 1200px;
        height: 600px;
        /* border:1px solid #ccc; */
    }
    ul,li{
        list-style: none;
    }

.tab .nav {
    float: left;
}
.tab .content {
    float: left;
    border-left:2px solid #ccc;
    border-right:2px solid #ccc;
    width:400px;
    height:400px;
}
.nav {
    height:200px;
    /* border-right:2px solid #ccc; */
    width:200px;
}
.nav li {
    line-height: 40px;
}
.content li{
    width:300px;
    height: 100px;
    display: none;
}
.nav .active {
    color:blue;
    font-size:28px;
}
.content .current {
    display: block;
    font-size: 30px;
    color:red;
}
    </style>
</head>
<body>
    <div class="tab" id='app'>
        <ul class="nav">
            <li v-if='index<3' v-on:click='tab(index)'  :class='index==currentindex ? "active":""'  v-for='(items,index) in navleft'>{{items.name}}</li>
        </ul>
        <ul class="content">
            <li :class='index==currentindex ? "current":""' v-for='(items,index) in navleft'>{{items.content}}</li>
        </ul>
        <ul class="nav">
            <li v-if='index>=3' v-on:click='tab(index)'  :class='index==currentindex ? "active":""'  v-for='(items,index) in navleft'>{{items.name}}</li>
        </ul>
    </div>
    <script src="js/vue.js"></script>
    <script>
    var vm = new Vue({
        el:'#app',
        data:{
            currentindex : 0,
            navleft:[
            {
                id:1,
                name:'section1',
                content:'section1'
            },
            {
                id:2,
                name:'section2',
                content:'section2'
            },
            {
                id:3,
                name:'section3',
                content:'section3'
            },
            {
                id:4,
                name:'section4',
                content:'section4'
            },
            {
                id:5,
                name:'section5',
                content:'section5'
            },
            {
                id:6,
                name:'section6',
                content:'section6'
            },]
        },
        methods: {
            tab(index){
                this.currentindex= index;
            }
        },
    })
    </script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值