InnerTab.vue 1.51 KB
<template>
  <div class="tab-box">
    <div class="tab-item-box" :style="{ width: width + 'vw' }">
      <div :class="['tab-item', tabActive == index ? 'tab-item-active' : '']" :style="{ 'padding-left': itemPadding + 'vw', 'padding-right': itemPadding + 'vw' }" v-for="(item, index) in list" :key="index" @click="changeTab(index)">
        {{ item }}
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'InnerTab',
  props: {
    list: {
      type: Array,
      default: () => []
    },
    width: Number,
    itemPadding: Number
  },
  data() {
    return {
      tabActive: 0
    }
  },

  mounted() {},

  methods: {
    // 切换tab
    changeTab(index) {
      this.tabActive = index
      this.$emit('changeTab', index)
    }
  }
}
</script>

<style lang="scss" scoped>
.tab-box {
  .tab-item-box {
    display: flex;
    margin: 0 auto;
    height: 2.67vh;
    background: #072545;
    line-height: 2.67vh;
    cursor: pointer;
    .tab-item {
      text-align: center;
      box-sizing: border-box;
      font-weight: 400;
      font-size: 12px;
      line-height: 2.67vh;
      color: #c9c9c9;
      &-active {
        color: #5894ff;
        background-image: -webkit-linear-gradient(left, #24d8ff, #7787ff);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        line-height: 2.22vh;
        font-weight: 600;
        border: 2px solid;
        border-image: linear-gradient(90deg, #074989, #30dcff, #074989) 1;
        box-sizing: border-box;
      }
    }
  }
}
</style>