cwg-tabs.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <view class="tabs-box">
  3. <view class="tab-title cwg-cursor" v-for="(row, index) in tabs" :key="index" @click="handleTabClick(index)"
  4. :class="{ active: props.cativeIndex == index }">
  5. <cwg-icon v-if="row.icon" :name="row.icon" :size="16"
  6. :color="props.cativeIndex == index ? '#fff' : '#333'" />
  7. <text>{{ row.name }}</text>
  8. </view>
  9. </view>
  10. </template>
  11. <script setup lang="ts">
  12. const props = defineProps({
  13. cativeIndex: {
  14. type: Number,
  15. default: 0
  16. },
  17. tabs: {
  18. type: Array,
  19. default: () => ([])
  20. }
  21. })
  22. const emit = defineEmits(['update:cativeIndex', 'tabClick'])
  23. const handleTabClick = (index: number) => {
  24. emit('update:cativeIndex', index);
  25. emit('tabClick', index);
  26. };
  27. </script>
  28. <style lang="scss" scoped>
  29. @import "@/uni.scss";
  30. .tabs-box {
  31. width: 100%;
  32. position: relative;
  33. display: flex;
  34. align-items: center;
  35. .tab-title {
  36. flex: 1;
  37. display: flex;
  38. align-items: center;
  39. gap: px2rpx(4);
  40. border: 1px solid #f3f4f6;
  41. font-size: px2rpx(16);
  42. padding: px2rpx(8) px2rpx(12);
  43. border-radius: px2rpx(2);
  44. background-color: var(--bs-bg-color);
  45. justify-content: center;
  46. color: var(--bs-emphasis-color);
  47. }
  48. .active {
  49. background-color: var(--color-error);
  50. color: #fff;
  51. border: 1px solid var(--bs-bg-color);
  52. }
  53. }
  54. </style>