cwg-tabs.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <view class="tabs-box">
  3. <view class="tab-title " 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: white;
  45. justify-content: center;
  46. }
  47. .active {
  48. background-color: var(--color-error);
  49. color: #fff;
  50. border: none;
  51. }
  52. }
  53. </style>