Vue tab选项卡

1 篇文章 0 订阅
1 篇文章 0 订阅
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="http://fsc.hzxy.edu.cn/css/leftnav2.css" >

<title>vue生命周期</title>
<style>
   .my-container{
       display: flex;
       align-items: center;
       flex-direction: column;
   }
   .my-tab{
       margin: 25px 0;
   }
   .tab-title{
        position: relative;
        left: 0;
        height: 40px;
        white-space: nowrap;
        font-size: 0;
       
        transition: all .2s;
        -webkit-transition: all .2s;
        list-style-type: none;
   }
   .tab-title li{
        display: inline-block;
        *display: inline;
        *zoom: 1;
        vertical-align: middle;
        font-size: 14px;
        transition: all .2s;
        -webkit-transition: all .2s;
        position: relative;
        line-height: 40px;
        min-width: 65px;
        padding: 0 30px;
        text-align: center;
        cursor: pointer;
   }
   .none{
       display: none;
   }
   .content{
       padding: 0px;
   }
   .this{
        color: #5B238E;
        font-size: 18px;
        font-weight: 600;
   }
   .this::after{
        border: none;
        border-radius: 0;
        border-bottom: 2px solid #5B238E;position: absolute;
        left: 0;
        top: 0;
        content: '';
        width: 100%;
        height: 41px;
        box-sizing: border-box;
        pointer-events: none;
   }

</style>
</head>

<body>
    <div id="app" class="my-container">
       <tabs :data="title" ></tabs>
    </div>
</body>
<script src="http://fsc.hzxy.edu.cn/js/jquery-3.2.1.min.js" ></script>
<script src="http://fsc.hzxy.edu.cn/js/bootstrap.min.js" ></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
    Vue.component('tabs',{
    props: ['data'],
    data(){
        return {
            active : 0
        }
    },
    methods: {
            toggle(e){
                console.log(e);
                this.active = e
            }
        },
    template: `<div class="my-tab"> 
                    <ul class="tab-title">
                        <li v-for="(item, index) in data" :key="index"   @click="toggle(index)" :class="[active === index ? 'this' :'']">{{item.text}}</li>
                    </ul>  
                    <div class="content">
                        <div class="tab-item" v-for="(item,index) in data" :class="[active === index ? 'tab-item' :'none']">
                            <img :src="item.url" width="400px" style="margin-top: 30px;margin-left: 50px;">
                        </div>
                    </div>
                </div>`      
    })
    let vm  = new Vue({
        el: '#app',
       
        data(){
            return{
               title:[
                   {text:"阿米娅爱你哟",url:"http://lumsn.gicp.net:2001/static/1.jpeg"},
                   {text:"推进之王爱你哟",url:"http://lumsn.gicp.net:2001/static/2.png"},
                   {text:"日光爱你哟",url:"http://lumsn.gicp.net:2001/static/3.jpeg"},
                   {text:"艾妮爱你哟",url:"http://lumsn.gicp.net:2001/static/4.png"},
               ]
            }
        },
       
      
    });

</script>


</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值