tabs.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <view class="tabs-n">
  3. <view class="h-tab">
  4. <view class="tab-1 " v-for="(item,index) in arrList" :key="item.key" :class="{'active':item.active}"
  5. @click="changeItem(index)">
  6. <text class="text1">{{item.name}}</text>
  7. </view>
  8. </view>
  9. <view class="h-content">
  10. <view v-show="activeIndex == 0">
  11. <slot name="slot1">
  12. </slot>
  13. </view>
  14. <view v-show="activeIndex == 1">
  15. <slot name="slot2">
  16. </slot>
  17. </view>
  18. <view v-show="activeIndex == 2">
  19. <slot name="slot3">
  20. </slot>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. props: {
  28. list: {
  29. type: Array,
  30. default: []
  31. },
  32. },
  33. mounted() {
  34. this.arrList = this.list
  35. },
  36. data() {
  37. return {
  38. activeIndex: 0,
  39. arrList:[],
  40. }
  41. },
  42. methods: {
  43. swiperChange(e) {
  44. this.arrList.map(e => e.active = false)
  45. this.activeIndex = e.target.current
  46. this.arrList[e.target.current].active = true
  47. },
  48. changeItem(index) {
  49. this.arrList.map(e => e.active = false)
  50. this.arrList[index].active = true
  51. this.activeIndex = index
  52. this.$emit('changeTab', index)
  53. }
  54. }
  55. }
  56. </script>
  57. <style scoped lang="scss">
  58. .tabs-n {
  59. .h-tab {
  60. display: flex;
  61. z-index: 0;
  62. width: 100vw;
  63. border: 1px solid #0c79cc;
  64. .active {
  65. color: #fff;
  66. background: #0c79cc !important;
  67. }
  68. .tab-1 {
  69. background: #fff;
  70. padding: 12rpx 0px;
  71. flex: 1;
  72. font-size: 32rpx;
  73. display: flex;
  74. align-items: center;
  75. justify-content: center;
  76. .text1 {
  77. text-align: center;
  78. }
  79. }
  80. }
  81. .h-content {
  82. min-height: calc(100vh - 80rpx);
  83. .swiper {
  84. min-height: calc(100vh - 80rpx);
  85. .swiperItem {}
  86. }
  87. }
  88. }
  89. </style>