1. 程式人生 > >vue實現選項卡切換效果

vue實現選項卡切換效果

效果如下:

說明:

這裡我使用的原理是利用vue中的v-show/顯示隱藏指令,當為true的時候顯示,為false的時候隱藏

1html程式碼:

<head>
    <meta charset="UTF-8">
    <base target="_blank">
    <title>vue實現選項卡切換效果</title>
    <script src="js/jquery-1.8.2.min.js"></script>
    <script src="js/vue.js"></
script> </head> <body> <div id="app"> <!--主體內容--> <div class="center"> <!--Tap選項卡部分--> <div class="center-left-tap"> <a href="javascript:void (0)" style="color: #1c1c1c;" class="current" @click="mt1">最新</a> <
a href="javascript:void (0)" class="a-hover" @click="mt2">B2C</a> <a href="javascript:void (0)" class="a-hover" @click="mt3">C2C</a> <a href="javascript:void (0)" class="a-hover" @click="mt4">傳統零售</a> <a href="javascript:void (0)" class
="a-hover" @click="mt5">其他</a> </div> <div class="container" id="container01"> <!--第一個 最新--> <div v-for="val in xuan" v-show="a"> <div class="con" style=""> <div class="center-left-body bg"> <div class="img-box1"> <img :src="val.img1" alt="" class="img-h b-img"> </div> <p><a href="detail-1.html" class="center-left-body-a1">{{val.h1}}</a></p> <p><a href="detail-1.html" class="center-left-body-a2">{{val.p1}}</a></p> <p class="mb-p">{{val.math}}</p> <img :src="val.img2" alt="" class="mb-img"> <p><a href="" class="tab-mt">{{val.a1}}</a><a href="" class="tab-mt">{{val.a2}}</a></p> </div> </div> </div> <!--第二個 B2C--> <div class="con" v-show="b"> <div class="center-left-body bg"> <div class="img-box1"> <img src="img-index/20181112_1542008037535.jpg" alt="" class="img-h b-img"> </div> <p><a href="detail-1.html" class="center-left-body-a1">夫妻店再升級 20萬小店接入零售通參加雙11</a></p> <p><a href="detail-1.html" class="center-left-body-a2">據瞭解,天貓雙十一期間,除20萬家街邊小店外,還有3000家天貓小店也將參與到線下活動中。</a></p> <p class="mb-p">2018-11-10 16:32</p> <img src="img-2/ico_pindao_dingyue.png" alt="" class="mb-img"> <p><a href="" class="tab-mt">企業服務</a><a href="" class="tab-mt">投融資</a></p> </div> <div class="center-left-body bg"> <div class="img-box1"> <img src="img-index/20181112_1541985913463.jpg" alt="" class="img-h b-img"> </div> <p><a href="detail-1.html" class="center-left-body-a1">夫妻店再升級 20萬小店接入零售通參加雙11</a></p> <p><a href="detail-1.html" class="center-left-body-a2">據瞭解,天貓雙十一期間,除20萬家街邊小店外,還有3000家天貓小店也將參與到線下活動中。</a></p> <p class="mb-p">2018-11-10 16:32</p> <img src="img-2/ico_pindao_dingyue.png" alt="" class="mb-img"> <p><a href="" class="tab-mt">企業服務</a><a href="" class="tab-mt">投融資</a></p> </div> </div> <!--第三個 C2C--> <div class="con" v-show="c"> <div class="center-left-body bg"> <div class="img-box1"> <img src="img-index/20181107_1541569944473.jpg" alt="" class="img-h b-img"> </div> <p><a href="detail-1.html" class="center-left-body-a1">夫妻店再升級 20萬小店接入零售通參加雙11</a></p> <p><a href="detail-1.html" class="center-left-body-a2">據瞭解,天貓雙十一期間,除20萬家街邊小店外,還有3000家天貓小店也將參與到線下活動中。</a></p> <p class="mb-p">2018-11-10 16:32</p> <img src="img-2/ico_pindao_dingyue.png" alt="" class="mb-img"> <p><a href="" class="tab-mt">企業服務</a><a href="" class="tab-mt">投融資</a></p> </div> <div class="center-left-body bg"> <div class="img-box1"> <img src="img-index/20181107_1541569944473.jpg" alt="" class="img-h b-img"> </div> <p><a href="detail-1.html" class="center-left-body-a1">夫妻店再升級 20萬小店接入零售通參加雙11</a></p> <p><a href="detail-1.html" class="center-left-body-a2">據瞭解,天貓雙十一期間,除20萬家街邊小店外,還有3000家天貓小店也將參與到線下活動中。</a></p> <p class="mb-p">2018-11-10 16:32</p> <img src="img-2/ico_pindao_dingyue.png" alt="" class="mb-img"> <p><a href="" class="tab-mt">企業服務</a><a href="" class="tab-mt">投融資</a></p> </div> <div class="center-left-body bg"> <div class="img-box1"> <img src="img-index/20181112_1542010837701.jpg" alt="" class="img-h b-img"> </div> <p><a href="detail-1.html" class="center-left-body-a1">夫妻店再升級 20萬小店接入零售通參加雙11</a></p> <p><a href="detail-1.html" class="center-left-body-a2">據瞭解,天貓雙十一期間,除20萬家街邊小店外,還有3000家天貓小店也將參與到線下活動中。</a></p> <p class="mb-p">2018-11-10 16:32</p> <img src="img-2/ico_pindao_dingyue.png" alt="" class="mb-img"> <p><a href="" class="tab-mt">企業服務</a><a href="" class="tab-mt">投融資</a></p> </div> </div> <!--第四個 傳統零售--> <div class="con" v-show="d"> <div class="center-left-body bg"> <div class="img-box1"> <img src="img-index/20181113_1542076349985.jpg" alt="" class="img-h b-img"> </div> <p><a href="detail-1.html" class="center-left-body-a1">夫妻店再升級 20萬小店接入零售通參加雙11</a></p> <p><a href="detail-1.html" class="center-left-body-a2">據瞭解,天貓雙十一期間,除20萬家街邊小店外,還有3000家天貓小店也將參與到線下活動中。</a></p> <p class="mb-p">2018-11-10 16:32</p> <img src="img-2/ico_pindao_dingyue.png" alt="" class="mb-img"> <p><a href="" class="tab-mt">企業服務</a><a href="" class="tab-mt">投融資</a></p> </div> <div class="center-left-body bg"> <div class="img-box1"> <img src="img-index/20181113_1542075324144.jpg" alt="" class="img-h b-img"> </div> <p><a href="detail-1.html" class="center-left-body-a1">夫妻店再升級 20萬小店接入零售通參加雙11</a></p> <p><a href="detail-1.html" class="center-left-body-a2">據瞭解,天貓雙十一期間,除20萬家街邊小店外,還有3000家天貓小店也將參與到線下活動中。</a></p> <p class="mb-p">2018-11-10 16:32</p> <img src="img-2/ico_pindao_dingyue.png" alt="" class="mb-img"> <p><a href="" class="tab-mt">企業服務</a><a href="" class="tab-mt">投融資</a></p> </div> <div class="center-left-body bg"> <div class="img-box1"> <img src="img-index/20181112_1542027463929.jpg" alt="" class="img-h b-img"> </div> <p><a href="detail-1.html" class="center-left-body-a1">夫妻店再升級 20萬小店接入零售通參加雙11</a></p> <p><a href="detail-1.html" class="center-left-body-a2">據瞭解,天貓雙十一期間,除20萬家街邊小店外,還有3000家天貓小店也將參與到線下活動中。</a></p> <p class="mb-p">2018-11-10 16:32</p> <img src="img-2/ico_pindao_dingyue.png" alt="" class="mb-img"> <p><a href="" class="tab-mt">企業服務</a><a href="" class="tab-mt">投融資</a></p> </div> <div class="center-left-body bg"> <div class="img-box1"> <img src="img-index/20181107_1541569944473.jpg" alt="" class="img-h b-img"> </div> <p><a href="detail-1.html" class="center-left-body-a1">夫妻店再升級 20萬小店接入零售通參加雙11</a></p> <p><a href="detail-1.html" class="center-left-body-a2">據瞭解,天貓雙十一期間,除20萬家街邊小店外,還有3000家天貓小店也將參與到線下活動中。</a></p> <p class="mb-p">2018-11-10 16:32</p> <img src="img-2/ico_pindao_dingyue.png" alt="" class="mb-img"> <p><a href="" class="tab-mt">企業服務</a><a href="" class="tab-mt">投融資</a></p> </div> </div> <!--第五個 其他--> <div class="con" v-show="e"> <div class="center-left-body bg"> <div class="img-box1"> <img src="img-index/20181113_1542091666106.jpg" alt="" class="img-h b-img"> </div> <p><a href="detail-1.html" class="center-left-body-a1">夫妻店再升級 20萬小店接入零售通參加雙11</a></p> <p><a href="detail-1.html" class="center-left-body-a2">據瞭解,天貓雙十一期間,除20萬家街邊小店外,還有3000家天貓小店也將參與到線下活動中。</a></p> <p class="mb-p">2018-11-10 16:32</p> <img src="img-2/ico_pindao_dingyue.png" alt="" class="mb-img"> <p><a href="detail-1.html" class="tab-mt">企業服務</a><a href="detail-1.html" class="tab-mt">投融資</a></p> </div> <div class="center-left-body bg"> <div class="img-box1"> <img src="img-index/20181113_1542091506167.jpg" alt="" class="img-h b-img"> </div> <p><a href="detail-1.html" class="center-left-body-a1">夫妻店再升級 20萬小店接入零售通參加雙11</a></p> <p><a href="detail-1.html" class="center-left-body-a2">據瞭解,天貓雙十一期間,除20萬家街邊小店外,還有3000家天貓小店也將參與到線下活動中。</a></p> <p class="mb-p">2018-11-10 16:32</p> <img src="img-2/ico_pindao_dingyue.png" alt="" class="mb-img"> <p><a href="detail-1.html" class="tab-mt">企業服務</a><a href="detail-1.html" class="tab-mt">投融資</a></p> </div> <div class="center-left-body bg"> <div class="img-box1"> <img src="img-index/20181113_1542089470929.jpg" alt="" class="img-h b-img"> </div> <p><a href="detail-1.html" class="center-left-body-a1">夫妻店再升級 20萬小店接入零售通參加雙11</a></p> <p><a href="detail-1.html" class="center-left-body-a2">據瞭解,天貓雙十一期間,除20萬家街邊小店外,還有3000家天貓小店也將參與到線下活動中。</a></p> <p class="mb-p">2018-11-10 16:32</p> <img src="img-2/ico_pindao_dingyue.png" alt="" class="mb-img"> <p><a href="detail-1.html" class="tab-mt">企業服務</a><a href="detail-1.html" class="tab-mt">投融資</a></p> </div> <div class="center-left-body bg"> <div class="img-box1"> <img src="img-index/20181107_1541569944473.jpg" alt="" class="img-h b-img"> </div> <p><a href="detail-1.html" class="center-left-body-a1">夫妻店再升級 20萬小店接入零售通參加雙11</a></p> <p><a href="detail-1.html" class="center-left-body-a2">據瞭解,天貓雙十一期間,除20萬家街邊小店外,還有3000家天貓小店也將參與到線下活動中。</a></p> <p class="mb-p">2018-11-10 16:32</p> <img src="img-2/ico_pindao_dingyue.png" alt="" class="mb-img"> <p><a href="detail-1.html" class="tab-mt">企業服務</a><a href="detail-1.html" class="tab-mt">投融資</a></p> </div> <div class="center-left-body bg"> <div class="img-box1"> <img src="img-index/20181112_1542008037535.jpg" alt="" class="img-h b-img"> </div> <p><a href="detail-1.html" class="center-left-body-a1">夫妻店再升級 20萬小店接入零售通參加雙11</a></p> <p><a href="detail-1.html" class="center-left-body-a2">據瞭解,天貓雙十一期間,除20萬家街邊小店外,還有3000家天貓小店也將參與到線下活動中。</a></p> <p class="mb-p">2018-11-10 16:32</p> <img src="img-2/ico_pindao_dingyue.png" alt="" class="mb-img"> <p><a href="detail-1.html" class="tab-mt">企業服務</a><a href="detail-1.html" class="tab-mt">投融資</a></p> </div> </div> </div> </div> </div><!--vue 結束--> </body>

2css程式碼:

<style>
    .center{width: 1160px;margin: 0 auto;}
    a{text-decoration: none;color: #595959;}
    a:hover{color: #1a79ff;}
    /*tap選項卡*/
    .center-left-tap{height: 58px;}
    .center-left-tap a{font-size: 16px;color: #999;margin-right: 37px;padding-bottom: 19px;}
    .a-hover:hover{color: #595959;}

    /*圖文重複內容*/
    .center-left-body{width: 820px;height: 127px;border-top:1px solid #ddd;margin-top: -15px;padding: 21px 0;margin-bottom: 20px;}
    .center-left-body img:nth-child(1){width: 190px;height: 127px;float: left;}
    .center-left-body-a1{float: left;margin-left: 20px;font-size: 18px;line-height: 26px;color: #333;margin-top: -175px;}
    .center-left-body-a2{float: left;margin-left: 210px;font-size: 16px;color: #595959;margin-top: -95px;word-wrap:break-word;}
    .mb-p{float: left;margin-top: -20px;margin-left: 210px;color:#999;}
    .mb-img{float: left;margin-top: -20px;margin-left: 15px;}
    .tab-mt{margin-right: -30px;margin-left: 50px;margin-top: -20px;float: left;}
    .bor-no{border: none;}
    .bg:hover{background-color:#efefef;}
</style>

3js:

<script>
    var vm = new Vue({
        el: '#app',
        data: {
            xuan: [],
            a: true,
            b: false,
            c: false,
            d: false,
            e: false,
        },
        mounted: function () {
            this.getData()
        },
        methods: {
            getData() {
                $.ajax({
                    type: 'get',
                    url: 'frame-1.json',
                    detaType: 'JSON',
                    success: function (data) {
                        vm.xuan = data.xuan
                    }
                })
            },

            //    選項卡
            mt1: function () {
                this.a = true
                this.b = false
                this.c = false
                this.d = false
                this.e = false
            },
            mt2: function () {
                this.a = false
                this.b = true
                this.c = false
                this.d = false
                this.e = false
            },
            mt3: function () {
                this.a = false
                this.b = false
                this.c = true
                this.d = false
                this.e = false
            },
            mt4: function () {
                this.a = false
                this.b = false
                this.c = false
                this.d = true
                this.e = false
            },
            mt5: function () {
                this.a = false
                this.b = false
                this.c = false
                this.d = false
                this.e = true
            }
        }
    });
</script>

應屆菜鳥,大佬勿噴...