TabBar.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <div class="tab-bar">
  3. <div
  4. class="tab-item"
  5. v-for="tab in tabs"
  6. :key="tab.path"
  7. @click="switchTab(tab.path)"
  8. :class="{ active: currentPath === tab.path }"
  9. >
  10. <img
  11. :src="getIcon(tab)"
  12. class="tab-icon"
  13. alt=""
  14. />
  15. <span>{{ tab.title }}</span>
  16. </div>
  17. </div>
  18. </template>
  19. <script>
  20. export default {
  21. name: 'TabBar',
  22. data() {
  23. return {
  24. currentPath: '/home',
  25. tabs: [
  26. {
  27. path: '/home',
  28. title: '首页',
  29. icon: 'index0.png',
  30. iconActive: 'index1.png'
  31. },
  32. {
  33. path: '/mall',
  34. title: '退休计划',
  35. icon: 'hang0.png',
  36. iconActive: 'hang1.png'
  37. },
  38. {
  39. path: '/dynamic', //邀请百姓
  40. // path: '/China', // 红旗中国
  41. // path: '/Medical', // 红旗医疗
  42. title: '邀请百姓',
  43. icon: 'gang0.png',
  44. iconActive: 'gang1.png'
  45. },
  46. {
  47. path: '/profile',
  48. title: '我的',
  49. icon: 'mine0.png',
  50. iconActive: 'mine1.png'
  51. }
  52. ]
  53. }
  54. },
  55. methods: {
  56. switchTab(path) {
  57. this.currentPath = path
  58. this.$router.push(path)
  59. },
  60. getIcon(tab) {
  61. return require(`@/assets/${this.currentPath === tab.path ? tab.iconActive : tab.icon}`)
  62. }
  63. },
  64. created() {
  65. this.currentPath = this.$route.path
  66. }
  67. }
  68. </script>
  69. <style lang="scss" scoped>
  70. .tab-bar {
  71. position: fixed;
  72. bottom: 0;
  73. left: 0;
  74. right: 0;
  75. height: 60px;
  76. background-color: #fff;
  77. display: flex;
  78. box-shadow: 0 -1px 5px rgba(0, 0, 0, 0.1);
  79. z-index: 999;
  80. .tab-item {
  81. flex: 1;
  82. display: flex;
  83. flex-direction: column;
  84. align-items: center;
  85. justify-content: center;
  86. color: #666;
  87. font-size: 14px;
  88. .tab-icon {
  89. width: 30px;
  90. height: 30px;
  91. margin-bottom: 2px;
  92. }
  93. &.active {
  94. color: #000;
  95. }
  96. }
  97. }
  98. </style>