Tab.vue 1.23 KB
<template>
  <div :class="[{ sticky: sticky }]">
    <van-tabs v-model="tabIndex" color="#3975C6" title-inactive-color="#BBB" title-active-color="#2c2c2c" @click="click" :key="updata">
      <template v-for="(i, index) in data">
        <van-tab :title="i" :key="index"></van-tab>
      </template>
    </van-tabs>
  </div>
</template>

<script type="text/ecmascript-6">
export default {
  name: 'Tab',
  props: {
    list: {
      type: Array,
      default: () => {
        return []
      }
    },
    sticky: Boolean,
    index: {
      type: Number,
      default: 0
    },
    updata: null
  },
  data () {
    return {
      tabIndex: this.index,
      data: this.list
    }
  },
  watch: {
    'index' (n) {
      this.tabIndex = n
    },
    'updata' (n) {
      this.data = this.list
      this.tabIndex = this.index
    },
    'list'(n){
      this.data = n
    }
  },
  mounted () {
  },
  methods: {
    click (tabIndex) {
      this.tabIndex = tabIndex
      this.$emit('change', tabIndex)
    }
  }
}
</script>

<style lang="scss">
.sticky {
  position: sticky;
  top: 0;
  z-index: 99;
}
.van-tabs__wrap {
  height: 50px !important;
}
.van-tab__text {
  transition: all 0.25s;
}
.van-tab--active {
  font-size: 16px !important;
}
</style>