app-switch-tab.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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="{'acitve-item': dIndex == index ? true : false}">
  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. },
  38. data() {
  39. return {}
  40. },
  41. computed: {
  42. dIndex: function () {
  43. return this.currentIndex;
  44. }
  45. },
  46. methods: {
  47. tabClick(index) {
  48. this.$emit('tabEvent', {
  49. currentIndex: index
  50. });
  51. }
  52. }
  53. }
  54. </script>
  55. <style scoped lang="scss">
  56. .item {
  57. height: 100%;
  58. }
  59. .tab-bottom-border {
  60. border-bottom: #{1rpx} solid $uni-weak-color-one;
  61. }
  62. .acitve-item {
  63. color: $uni-important-color-red;
  64. border-bottom: #{4rpx} solid $uni-important-color-red;
  65. }
  66. </style>