app-switch-tab.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <view class='app-switch-tab dir-left-nowrap'
  3. :class="isborderBottom ? 'tab-bottom-border' : ''"
  4. :style="{'background-color':bgColor,'height': tabHeight + 'rpx'}">
  5. <view v-for="(item, index) in list" :key="index" @click='tabClick(index)' class='box-grow-1 main-center'>
  6. <view class="item cross-center" :class="dIndex == index ? theme + '-m-text active-item ' + theme : 'no-active-item'">
  7. {{item.name}}
  8. </view>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. props: {
  15. bgColor: {
  16. type: String,
  17. default: '#fff'
  18. },
  19. list: {
  20. type: Array,
  21. default: []
  22. },
  23. tabHeight: {
  24. // 高度
  25. type: Number,
  26. default: 80
  27. },
  28. currentIndex: {
  29. // 当前点击的元素索引
  30. type: Number,
  31. default: 0,
  32. },
  33. isborderBottom: {
  34. type: Boolean,
  35. default: true
  36. },
  37. theme: {
  38. type: String,
  39. default: 'default'
  40. }
  41. },
  42. data() {
  43. return {}
  44. },
  45. computed: {
  46. dIndex: function () {
  47. return this.currentIndex;
  48. }
  49. },
  50. methods: {
  51. tabClick(index) {
  52. this.$emit('tabEvent', {
  53. currentIndex: index
  54. });
  55. }
  56. }
  57. }
  58. </script>
  59. <style scoped lang="scss">
  60. .item {
  61. height: 100%;
  62. }
  63. .tab-bottom-border {
  64. border-bottom: #{1rpx} solid $uni-weak-color-one;
  65. }
  66. .no-active-item {
  67. border-bottom: #{4rpx} solid trasparent;
  68. }
  69. .active-item {
  70. border-bottom: #{4rpx} solid;
  71. }
  72. .default-m-text {
  73. color: #ff4544;
  74. }
  75. .blue-m-text {
  76. color: #446dfd;
  77. }
  78. </style>