vue tab选项卡2 小案例

最终效果:

<template>
  <div id="app" class="box">
  <ul class="tabs clearfix">
    <li v-for="(tab,index) in tabsName">
      <a href="javascript:;" rel="external nofollow" class="tab-link" @click="tabsSwitch(index)" v-bind:class="{active:tab.isActive}">{{tab.name}}</a>
    </li>
  </ul>
  <div class="cards">
    <div class="tab-card" style="display: block;">这里是HTML教程</div>
    <div class="tab-card">欢迎来到CSS模块</div>
    <div class="tab-card">嗨,这里是Vue</div>
  </div>
</div>
</template>

<script>
    export default {
      name: "tabs1",
      data() {
        return {
          tabsName: [{
            name: "HTML",
            isActive: true
          }, {
            name: "CSS",
            isActive: false
          }, {
            name: "Vue",
            isActive: false
          }],
          active: false
        }
      },
      methods: {
        tabsSwitch: function(tabIndex) {
          var tabCardCollection = document.querySelectorAll(".tab-card"),
            len = tabCardCollection.length;
          for(var i = 0; i < len; i++) {
            tabCardCollection[i].style.display = "none";
            this.tabsName[i].isActive = false;
          }
          this.tabsName[tabIndex].isActive = true;
          tabCardCollection[tabIndex].style.display = "block";
        }
      }
    }
</script>

<style scoped>
  * {
    padding: 0;
    margin: 0;
  }
  .box {
    width: 70%;
    height: 200px;
    /*margin: 0 auto;*/
    border: 1px solid #000;
  }
  .tabs{
    width: 100%;
    display: flex;
    justify-content: space-between;
  }
  .tabs li {
    width: 100%;
    float: left;
    margin-right: 8px;
    list-style: none;
  }
  .tabs .tab-link {
    display: block;
    width: 104%;
    height: 49px;
    text-align: center;
    line-height: 49px;
    background-color: #5597B4;
    color: #fff;
    text-decoration: none;
  }
  .tabs .tab-link.active {
    height: 47px;
    border-bottom: 2px solid #E35885;
    transition: .3s;
    /*transform: scale(1.2);*/
    background-color: midnightblue;
  }
  .cards {
    float: left;
  }
  .cards .tab-card {
    display: none;
  }
  .clearfix:after {
    content: "";
    display: block;
    height: 0;
    clear: both;
  }
  .clearfix {
    zoom: 1;
  }
</style>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值