icon-label-nav.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <view class="slot">
  3. <view class="tab" v-for="(item, index) in ops" :key="index" :class="{ active: currentTab == index }" @click="changeTab(item, index)">
  4. <view class="icon">
  5. <u-image width="56rpx" height="56rpx" :src="item.iconActive" v-show="currentTab == index"></u-image>
  6. <u-image width="56rpx" height="56rpx" :src="item.icon" v-show="currentTab != index"></u-image>
  7. </view>
  8. <view class="label">{{ item.label }}</view>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. props: {
  15. ops: {
  16. type: Array,
  17. default: () => {
  18. return [];
  19. }
  20. }
  21. },
  22. data() {
  23. return {
  24. currentTab: 0
  25. };
  26. },
  27. methods: {
  28. // 切换tab
  29. changeTab(item, index) {
  30. this.currentTab = index
  31. this.$emit('change', { item, index });
  32. }
  33. }
  34. };
  35. </script>
  36. <style lang="scss" scoped>
  37. .slot {
  38. display: flex;
  39. justify-content: space-around;
  40. align-items: center;
  41. background-color: $app-theme-bg-color;
  42. height: 150rpx;
  43. .tab {
  44. .icon {
  45. display: flex;
  46. justify-content: center;
  47. margin-bottom: 14rpx;
  48. }
  49. .label {
  50. font-size: 26rpx;
  51. color: $app-theme-card-gray-deep-color;
  52. }
  53. &.active {
  54. .label {
  55. color: $app-theme-text-black-color;
  56. }
  57. }
  58. }
  59. }
  60. </style>