微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

vue 之封装一个简单的tabs组件

目录

在这里插入图片描述

vue 之封装一个简单的tabs组件

<!-- Tabs标签页 -->
<template>
  <div class="tabs_wrapt">
    <div
      v-for="(item,index) in titles"
      :key="item"
      @click="itemClcik(index)"
      :class="active === index ? 'active': '' "
    >
      {{ item }}
      <div class="line" v-if="active === index"></div>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  components: {},
  data() {
    return {
      active: 0,
      titles: [
        "集团指标",
        "财务费用分析",
        "财务费用率分析",
        "信保额分析",
        "信保费分析"
      ]
    };
  },
  methods: {
    itemClcik(index) {
      this.active = index;
      this.$emit("tabsClick", index);
    }
  }
};
</script>
<style  lang="scss" scoped>
.tabs_wrapt {
  display: flex;
  flex-wrap: Nowrap;
  height: 40px;
  line-height: 40px;
  background: #ccc;
  overflow-x: scroll;

  &::-webkit-scrollbar {
    display: none;
  }

  & > div {
    height: 100%;
    background: yellow;
    padding: 0 6px;
    //不让主轴压缩
    flex-shrink: 0;
    font-family: PingFangSC-Regular;
    font-size: 12px;
    color: #333333;
    text-align: left;
  }
  .active {
    position: relative;
    font-family: PingFangSC-Medium;
    font-size: 17px;
    color: #000000;
    text-align: left;

    .line {
      position: absolute;
      top: 34px;
      left: 50%;
      transform: translateX(-50%);
      width: 24px;
      height: 2px;
      background: #1e87f0;
      border-radius: 1.5px;
    }
  }
}
</style>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐