vue tab点击切换组件

vue yekong 1254℃

Vue开发时,经常会遇到写切换,每次都要手写一般很累人,存个备份留待后期复用。
vue tab点击切换组件

<template>
  <div class="tabs">
    <div class="tab cur" :class="{active:active==index}" @click="getactive(index)" v-for="(item,index) in list"
         :key="index"><span>{{ item }}</span>
    </div>
  </div>
</template>

<script>

export default {
  name: "tabs",
  components: {},
  props: {
    id: {
      type: String,
      default() {
        return '';
      }
    }
  },
  data() {
    return {
      list: ['今天', '7日', '30日'],
      active: 0
    }
  },
  watch: {},
  mounted() {
  },
  methods: {
    getactive(e) {
      this.active = e
      this.$emit('getactive', e)
    }
  }
}
</script>

<style lang="scss" scoped>
.tabs {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: nowrap;
  flex-direction: row;

  .tab {
    width: 70px;
    height: 31px;
    background: url("../../assets/orderbg.png") no-repeat;
    background-size: 100% 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
    flex-direction: row;
    margin-right: 10px;
    margin-left: 10px;

    span {
      font-size: 14px;
      font-family: PingFang;
      font-weight: 500;
      color: #FFFFFF;
    }
  }

  .tab.active {
    background: url("../../assets/cheweibg.png") no-repeat;
    background-size: 100% 100%;
  }
}
</style>

喜欢 (0)