SelectBar.vue 1.38 KB
<template>
  <div class="select-tab flex" v-if="data.length > 0">
    <template v-for="(i) in data">
      <div @click="click(i)" :class="['item', tabIndex == i.value ? 'active' : '']" :key="i.value">{{ i.text }}</div>
    </template>
  </div>
</template>

<script type="text/ecmascript-6">
export default {
  name: 'SelectBar',
  props: {
    list: {
      type: Array,
      default: () => {
        return []
      }
    },
    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
    }
  },
  mounted () {
  },
  methods: {
    click (data) {
      this.tabIndex = data.value
      this.$emit('change', this.tabIndex)
    }
  }
}
</script>

<style lang="scss" scoped>
.select-tab {
  margin: 10px 16px;
  height: 28px;
  background: #ebeff5;
  border-radius: 6px;
  box-sizing: border-box;
  .item {
    font-size: 14px;
    font-weight: 400;
    color: #666666;
    line-height: 28px;
    flex: 1;
    text-align: center;
  }
  .active {
    height: 24px;
    background: #ffffff;
    box-shadow: 0px 1px 2px 0px rgba(94, 97, 102, 0.2);
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.04);
    color: #3975c6;
    line-height: 24px;
  }
}
</style>