云链智安app
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

top-tabbar.vue 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <view class="home">
  3. <!-- 顶部导航栏 -->
  4. <view class="uni-top-tabbar">
  5. <scroll-view scroll-x class="uni-swiper-tab">
  6. <block v-for="(tabBar, index) in tabBars" :key="index">
  7. <view
  8. class="swiper-tab-list"
  9. :class="{ active: tabIndex === index }"
  10. :style="{ color: tabIndex === index ? selectedTextColor : textColor }"
  11. @click="toggleTab(index)"
  12. >
  13. {{ tabBar.name }}
  14. <view
  15. class="swiper-tab-line"
  16. :style="{ backgroundColor: tabIndex === index ? selectedBottomColor : bgColor }"
  17. ></view>
  18. </view>
  19. </block>
  20. </scroll-view>
  21. </view>
  22. </view>
  23. </template>
  24. <script setup>
  25. // 定义 props
  26. const props = defineProps({
  27. // 选中标签栏的索引
  28. tabIndex: {
  29. type: Number,
  30. default: 0,
  31. },
  32. // 导航栏标签内容
  33. tabBars: {
  34. type: Array,
  35. default: () => [
  36. { name: '标签1', id: 1 },
  37. { name: '标签2', id: 2 },
  38. { name: '标签3', id: 3 },
  39. { name: '标签4', id: 4 },
  40. { name: '标签5', id: 5 },
  41. { name: '标签6', id: 6 },
  42. ],
  43. },
  44. // 选中时底部横条颜色
  45. selectedBottomColor: {
  46. type: String,
  47. default: '#30c58d',
  48. },
  49. // 导航区背景颜色
  50. bgColor: {
  51. type: String,
  52. default: '',
  53. },
  54. // 选中时文字颜色
  55. selectedTextColor: {
  56. type: String,
  57. default: '#343434',
  58. },
  59. // 默认文本颜色
  60. textColor: {
  61. type: String,
  62. default: '#7d7e80',
  63. },
  64. });
  65. // 定义 emits
  66. const emit = defineEmits(['toggleToptab']);
  67. // 点击导航栏标签触发
  68. const toggleTab = (index) => {
  69. emit('toggleToptab', index);
  70. };
  71. </script>
  72. <style lang="scss" scoped>
  73. .uni-top-tabbar {
  74. /* 以下3项设置用于开启底部阴影显示 */
  75. /* position: relative;
  76. z-index: 1;
  77. overflow: visible; */
  78. .uni-swiper-tab {
  79. height: 100rpx;
  80. // 设置底部阴影
  81. // box-shadow: rgba(170, 170, 170, 0.5) 0 2rpx 8rpx 0;
  82. .swiper-tab-list {
  83. font-size: 28rpx;
  84. font-weight: normal;
  85. line-height: 82rpx;
  86. // 设置标签宽度
  87. width: 48%;
  88. display: flex;
  89. flex-direction: column;
  90. align-items: center;
  91. }
  92. .active {
  93. .swiper-tab-line {
  94. height: 6rpx;
  95. width: 100%;
  96. // margin: auto;
  97. }
  98. }
  99. }
  100. }
  101. </style>