index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <van-tabs :class="clazz" :active="tabActive" :ellipsis="false" @change="tabChange">
  3. <template v-for="(item, index) in tabs">
  4. <van-tab class="u-tab" :title="item.label" :name="item.value"></van-tab>
  5. </template>
  6. </van-tabs>
  7. </template>
  8. <script>
  9. export default {
  10. options: {
  11. styleIsolation: 'shared'
  12. },
  13. props: {
  14. tabStyle: String,
  15. active: [String, Number],
  16. tabs: [Array]
  17. },
  18. computed: {
  19. clazz() {
  20. if (this.tabStyle === 'default') {
  21. return 'u-tabs u-tabs-detault'
  22. } else {
  23. return 'u-tabs'
  24. }
  25. }
  26. },
  27. watch: {
  28. active(val) {
  29. // this.tabActive = val
  30. }
  31. },
  32. data() {
  33. return {
  34. tabActive: undefined,
  35. data: [{
  36. label: '表面贴装',
  37. value: 1
  38. }, {
  39. label: '线束加工',
  40. value: 2
  41. }, {
  42. label: '工厂自动化',
  43. value: 3
  44. }, {
  45. label: '点胶注胶',
  46. value: 4
  47. }, {
  48. label: '电子制造服务',
  49. value: 5
  50. }, {
  51. label: '未来服务',
  52. value: 6
  53. }]
  54. }
  55. },
  56. created() {
  57. // this.tabActive = this.active
  58. console.log("===================")
  59. console.log(this.tabStyle)
  60. },
  61. mounted() {
  62. },
  63. methods: {
  64. tabChange(e) {
  65. const detail = e.detail
  66. e.detail = {
  67. index: detail.index,
  68. label: detail.title,
  69. value: detail.name
  70. }
  71. this.tabActive = e.detail.name
  72. this.$emit('update:active', this.tabActive)
  73. this.$emit('change', e)
  74. }
  75. }
  76. }
  77. </script>
  78. <style lang="scss">
  79. .u-tabs{
  80. --tabs-line-height: 64rpx;
  81. --tabs-card-height: 64rpx;
  82. --tabs-bottom-bar-height: rpx;
  83. --tab-active-text-color: #E57519;
  84. --tab-background-color: #F5F5F5;
  85. --tab-active-background-color: #F9E3D1;
  86. --tab-margin-right: 10rpx;
  87. --tab-border-radius: 20rpx;
  88. .van-tab{
  89. font-size: $fontSize2;
  90. line-height: 50rpx;
  91. }
  92. .van-tabs--line{
  93. height: 50rpx;
  94. }
  95. .van-tabs__scroll--line{
  96. height: 100%;
  97. }
  98. }
  99. .u-tabs.u-tabs-detault{
  100. --tabs-line-height: 48rpx;
  101. --tabs-card-height: 50rpx;
  102. --tabs-bottom-bar-height: 0;
  103. --tab-active-text-color: #FFFFFF;
  104. --tab-background-color: #FFFFFF;
  105. --tab-active-background-color: #E57519;
  106. --tab-margin-right: 13rpx;
  107. --tab-border-radius: 6rpx;
  108. .van-tabs__nav{
  109. padding: 0;
  110. }
  111. .van-tab{
  112. font-size: $fontSize1;
  113. border: 1rpx solid #7D7D7D;
  114. height: 50rpx;
  115. color: #7D7D7D;
  116. }
  117. .van-tab--active{
  118. border-color: #E57519!important;
  119. color: #FFFFFF;
  120. }
  121. .van-tabs__wrap--scrollable .van-tab--complete{
  122. flex: none!important;
  123. padding: 0 32rpx;
  124. }
  125. .van-tabs--line{
  126. height: 50rpx;
  127. }
  128. }
  129. .u-tab{
  130. margin-right: 20rpx;
  131. }
  132. </style>