tab-item.vue 2.05 KB
Newer Older
Nature's avatar
Nature committed
1
<template>
Nature's avatar
Nature committed
2 3 4 5
  <section class="h-tab-item" @click="titleClick">
    <div class="h-item">
      <slot/>
    </div>
Nature's avatar
Nature committed
6 7
    <div v-show="showDivider" class="tab-divider"/>
  </section>
Nature's avatar
Nature committed
8

Nature's avatar
Nature committed
9 10 11 12 13 14
</template>

<script>
export default {
  name: 'TabItem',
  data () {
Nature's avatar
Nature committed
15 16 17
    return {

    }
Nature's avatar
Nature committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
  },
  computed: {
    showDivider () {
      return this.$parent.showDivider
    },
  },
  mounted () {
    this.$parent && this.$parent.items.push(this)
    this.$el.setAttribute('data-index', this.$parent.items.length - 1)
  },
  destroyed () {
    this.$parent && this.$parent.items.splice(this.$parent.items.indexOf(this), 1)
  },
  methods: {
    titleClick (event) {
      let vm = this
      vm.$parent.items.forEach(item => {
        item.$el.classList.remove('activated')
      })
      let clickIndex = Number(event.currentTarget.getAttribute('data-index'))
      event.currentTarget.classList.remove('activated')
      event.currentTarget.classList.add('activated')
Nature's avatar
Nature committed
40 41
      let clientWidth = event.currentTarget.clientWidth
      vm.$parent.actived(clickIndex, clientWidth)
Nature's avatar
Nature committed
42
    },
Nature's avatar
Nature committed
43

Nature's avatar
Nature committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
  },
}
</script>

<style lang="less">
  .hls-switch-tab {

    .tab-content {
      width: 100%;
      display: flex;
      align-items: center;

      .h-tab-item {
        width: 100%;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
Nature's avatar
Nature committed
62

Nature's avatar
Nature committed
63 64 65 66 67 68 69 70 71
        .h-item {
          //width: 100%;
          font-size: 14px;
          height: 40px;
          color: #7c828d;
          line-height: 15px;
          display: flex;
          align-items: center;
          justify-content: center;
Nature's avatar
Nature committed
72
         // padding: 0 3px;
Nature's avatar
Nature committed
73
          border-bottom: 1px solid rgba(255, 255, 255, .0); /*no*/
Nature's avatar
Nature committed
74 75
        }

Nature's avatar
Nature committed
76
        &.activated {
Nature's avatar
Nature committed
77 78 79 80 81 82
          .h-item {
            color: #1e8ceb;
            border-bottom: 1px solid #1e8ceb; /*no*/
          }
        }
        .tab-divider {
Nature's avatar
Nature committed
83 84 85 86 87 88 89 90 91
          width: 1px; /*no*/
          height: 50%;
          background-color: rgb(214, 217, 218);
        }

        &:last-child {
          .tab-divider {
            width: 0px;
          }
Nature's avatar
Nature committed
92 93 94 95 96 97
        }
      }
    }
  }

</style>