Tab.vue 1.41 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="{ width: (itemWidth) + 'vw','padding-left': paddingWidth + 'vw','padding-right': paddingWidth + 'vw' }" v-for="(item, index) in list" :key="index" @click="changeTab(index)">
        {{ item }}
      </div>
    </div>
  </div>
</template>

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

  mounted() {},

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

<style lang="scss" scoped>
.tab-box {
  margin: 0 auto;
  .tab-item-box {
    display: flex;
    padding: 0.44vh 0.28vw;
    border: 2px solid;
    border-image: linear-gradient(90deg, #074989, #30dcff, #074989) 1;
    background-image: linear-gradient(180deg, #001948 0%, #00223c 99%);
    cursor: pointer;
    .tab-item {
      padding: 0.56vh 0;
      text-align: center;
      box-sizing: border-box;
      font-weight: 400;
      font-size: 16px;
      color: #ffffffbf;
      &-active {
        background-image: linear-gradient(270deg, #6578ff 0%, #079ff1 100%);
        color: #ffffff;
      }
    }
  }
}
</style>