vue 弧形tab切换组件

csharp 复制代码
<template>
<div class="tab">
  <div class="tab-item" v-for="(item,index) in tabList" :key="index" :class="{'active':index == activeIndex}" @click="changeTab(index)">
    <div class="item">
      {{item.title}}
    </div>
  </div>
</div>
</template>

<script>
export default {
  name: 'tabIndex',
  props: {
    tabList: {
      type: Array,
      default: () => [{
          title: '已完成',
        },
        {
          title: '未完成',
        },
        {
          title: '已结束',
        },
      ]
    }
  },
  data() {
    return {
      activeIndex: 0,
    }
  },
  methods: {
    changeTab(index) {
      this.activeIndex = index;
      this.$emit('click', index);
    }
  },

}
</script>

<style lang="scss" scoped>
.tab {
  display: flex;
  justify-content: space-around;
  .tab-item {
    background-color: #eee;
    width: 150px;
    height: 50px;
    text-align: center;
    line-height: 50px;
    margin: 0 10px;
    border-radius: 10px 10px 0 0;
    position: relative;
    transform: perspective(30px) rotateX(10deg);
    .item {
      transform: perspective(30px) rotateX(-10deg);
      margin-top: 5px;
    }
  }
  $w:30px;
  $w1:29px;
  $actColor:#0056f5;
  .tab-item::after,
  .tab-item::before {
    position: absolute;
    content: '';
    width: $w;
    height: $w;
    bottom: 0;
    background-color: #eee;
    border: none;
  }
  .tab-item::after {
    right: -$w1;
    background: radial-gradient(circle at 100% 0, transparent $w, #eee $w);
  }
  .tab-item::before {
    left: -$w;
    background: radial-gradient(circle at 0 0, transparent $w, #eee $w);
  }
  .active {
    z-index: 10;
    &::after {
      background: radial-gradient(circle at 100% 0, transparent $w, $actColor $w);
    }
    &::before {
      background: radial-gradient(circle at 0 0, transparent $w, $actColor $w);
    }
    background-color: $actColor;
    color: #fff;
  }
}
</style>
相关推荐
胡志辉的博客15 分钟前
深入浅出理解浏览器事件循环:从一道输出题讲到 Chrome 源码
前端·javascript·chrome·chromium·event loop
代码不加糖24 分钟前
js中不会冒泡的事件有哪些?
前端·javascript·vue.js
懂懂tty39 分钟前
Vue2与Vue3之间API差异
前端·javascript·vue.js
老毛肚1 小时前
软件测试期末考试
vue.js
小二·1 小时前
Next.js 15 全栈开发实战
开发语言·javascript·ecmascript
杨若瑜2 小时前
本地开发环境慢?localhost的锅!
vue.js
Rain5092 小时前
2.1 Nest.js 项目初始化与模块化架构
开发语言·前端·javascript·后端·架构·数据分析·node.js
拾年2754 小时前
从零手写 Ajax:用原生 XHR 搭建前后端交互全流程
前端·javascript·ajax
拉勾科研工作室4 小时前
区块链工程毕业论文题目【249个】
开发语言·javascript
小林ixn4 小时前
你以为你懂 + 号?看完这篇 Bun + TS 实战,才发现以前全写错了
前端·javascript·typescript