wuc-tab.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <scroll-view class="wuc-tab" :class="tabClass" :style="tabStyle" scroll-with-animation scroll-x :scroll-left="scrollLeft">
  3. <div v-if="!textFlex">
  4. <div class="wuc-tab-item" :class="[index === tabCur ? selectClass + ' cur':'']" v-for="(item,index) in tabList" :key="index" :id="index" @tap="tabSelect(index,$event)">
  5. <text :class="item.icon"></text>
  6. <span>{{item.name}}</span>
  7. </div>
  8. </div>
  9. <div class="flex text-center" v-if="textFlex">
  10. <div class="wuc-tab-item flex-sub" :class="index === tabCur ? selectClass + ' cur':''" v-for="(item,index) in tabList" :key="index" :id="index" @tap="tabSelect(index,$event)">
  11. <text :class="item.icon"></text>
  12. <span>{{item.name}}</span>
  13. </div>
  14. </div>
  15. </scroll-view>
  16. </template>
  17. <script>
  18. export default {
  19. name: 'wuc-tab',
  20. data() {
  21. return {};
  22. },
  23. props: {
  24. tabList: {
  25. type: Array,
  26. default() {
  27. return [];
  28. }
  29. },
  30. tabCur: {
  31. type: Number,
  32. default() {
  33. return 0;
  34. }
  35. },
  36. tabClass: {
  37. type: String,
  38. default() {
  39. return '';
  40. }
  41. },
  42. tabStyle: {
  43. type: String,
  44. default() {
  45. return '';
  46. }
  47. },
  48. textFlex: {
  49. type: Boolean,
  50. default() {
  51. return false;
  52. }
  53. },
  54. selectClass: {
  55. type: String,
  56. default() {
  57. return 'text-blue';
  58. }
  59. }
  60. },
  61. methods: {
  62. tabSelect(index, e) {
  63. if (this.currentTab === index) return false;
  64. this.$emit('update:tabCur', index);
  65. this.$emit('change', index);
  66. }
  67. },
  68. computed: {
  69. scrollLeft() {
  70. return (this.tabCur - 1) * 60;
  71. }
  72. }
  73. };
  74. </script>
  75. <style>
  76. div,
  77. scroll-view,
  78. swiper {
  79. box-sizing: border-box;
  80. }
  81. .wuc-tab {
  82. white-space: nowrap;
  83. }
  84. .wuc-tab-item {
  85. height: 90upx;
  86. display: inline-block;
  87. line-height: 90upx;
  88. margin: 0 10upx;
  89. padding: 0 20upx;
  90. }
  91. .wuc-tab-item.cur {
  92. border-bottom: 4upx solid;
  93. }
  94. .wuc-tab.fixed {
  95. position: fixed;
  96. width: 100%;
  97. top: 0;
  98. z-index: 1024;
  99. box-shadow: 0 1upx 6upx rgba(0, 0, 0, 0.1);
  100. }
  101. .flex {
  102. display: flex;
  103. }
  104. .text-center {
  105. text-align: center;
  106. }
  107. .flex-sub {
  108. flex: 1;
  109. }
  110. .text-blue{
  111. color:#0081ff;
  112. }
  113. .text-white{
  114. color:#ffffff;
  115. }
  116. .bg-white{
  117. background-color: #ffffff;
  118. }
  119. .bg-blue{
  120. background-color: #0081ff;
  121. }
  122. .text-orange{
  123. color: #f37b1d
  124. }
  125. .text-xl {
  126. font-size: 36upx;
  127. }
  128. </style>