fav-tab-block.vue 1.56 KB
<template>
  <div class="tabs-wrap">
    <ul class="tabs-list">
      <li v-for="(item, index) in tabList" :key="index" @click="changeType(index, true)">
        <div class="tabs-item" :class="{'active': active === index}">
          {{item.name}}
          <span class="t-num" :class="{'active': active === index}">{{item.subname}}</span>
        </div>
      </li>
    </ul>
  </div>
</template>


<script>
export default {
  props: {
    activeIndex: Number
  },
  data() {
    return {
      tabList: [
        {name: '内容', subname: 'POST', type: 1},
        {name: '收藏', subname: 'COLLECT', type: 2},
      ],
      active: ''
    };
  },
  created() {
    this.changeType(this.activeIndex);
  },
  methods: {
    changeType(index) {
      if (!this.tabList[index]) {
        index = 0;
      }

      this.active = index;

      this.$emit('change', index);
    },
    computeCurrentTab() {
      this.changeType(this.activeIndex || 0);
    }
  },
  watch: {
    activeIndex: 'computeCurrentTab'
  }
};
</script>


<style>
  .tabs-wrap {
    background-color: #fff;
    display: flex;
    height: 96px;
    justify-content: center;
    align-items: center;

    .tabs-list {
      display: flex;

      li {
        font-size: 28px;
        color: #b0b0b0;
        font-weight: 300;
      }

      .tabs-item {
        padding: 28px 40px;
      }

      .t-num {
        color: #b0b0b0;
        font-size: 20px;
        zoom: 0.6;
        margin-left: -4px;
      }

      .active {
        color: #444;
        font-weight: bold;
        position: relative;
      }
    }
  }
</style>