tab.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <div class="tabs">
  3. <div class="tab-item" v-for="(item, index) of data" :key="item" @click="select(index, item)" :class="{ active: activeIndex == index }">
  4. {{ item.text }}
  5. </div>
  6. </div>
  7. </template>
  8. <script>
  9. export default {
  10. // 传参
  11. props: {
  12. // tab 项
  13. data: {
  14. type: Array,
  15. default: () => [
  16. {
  17. id: "day",
  18. text: "日",
  19. },
  20. {
  21. id: "month",
  22. text: "月",
  23. },
  24. {
  25. id: "year",
  26. text: "年",
  27. },
  28. ],
  29. },
  30. },
  31. // 事件
  32. emits: {
  33. select: null,
  34. },
  35. data() {
  36. return {
  37. activeIndex: 0,
  38. };
  39. },
  40. methods: {
  41. select(index, item) {
  42. this.activeIndex = index;
  43. this.$emit("select", item);
  44. },
  45. },
  46. };
  47. </script>
  48. <style lang="less">
  49. .tabs {
  50. display: flex;
  51. color: @font-color;
  52. margin-bottom: 1.111vh;
  53. font-size: @fontsize;
  54. .tab-item {
  55. padding: 0.37vh 1.852vh;
  56. cursor: pointer;
  57. &.active {
  58. color: @green;
  59. position: relative;
  60. background-image: @greenLinearTop;
  61. &::after {
  62. content: "";
  63. position: absolute;
  64. width: 100%;
  65. height: 0.463vh;
  66. border: 0.093vh solid @green;
  67. border-top: 0;
  68. left: 0;
  69. bottom: 0;
  70. box-sizing: border-box;
  71. }
  72. }
  73. }
  74. }
  75. </style>