tabbar.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view>
  3. <u-tabbar :border="true" :fixed="true" :placeholder="true" :safeAreaInsetBottom="true" zIndex="9999"
  4. :value="current?current:0" activeColor="#C29556" inactiveColor="#AAAFC4" @change="changeTab">
  5. <u-tabbar-item v-for="(item,index) in list" :key="index" :name="item.id" :text="item.text" style="width: 20%">
  6. <image slot="active-icon" :src="item.selectedIconPath" class="u-page__item__slot-icon"></image>
  7. <image slot="inactive-icon" :src="item.iconPath" class="u-page__item__slot-icon-index"></image>
  8. </u-tabbar-item>
  9. </u-tabbar>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. name: "tabbar",
  15. data() {
  16. return {
  17. list: [{
  18. id: 0,
  19. // 图片更换成自己的哈
  20. selectedIconPath: "../../static/index-b.png",
  21. iconPath: "../../static/index-a.png",
  22. text: '首页',
  23. pagePath: "pages/home/index"
  24. },
  25. {
  26. id: 1,
  27. selectedIconPath: "../../static/pd-b.png",
  28. iconPath: "../../static/pd-a.png",
  29. text: '好物',
  30. pagePath: "pages/productCenter/productCenter"
  31. },
  32. {
  33. id: 2,
  34. pagePath: "pages/activity/activity",
  35. text: "活动",
  36. iconPath: "../../static/hd-a.png",
  37. selectedIconPath: "../../static/hd-b.png"
  38. },
  39. {
  40. id: 3,
  41. selectedIconPath: "../../static/cart-b.png",
  42. iconPath: "../../static/cart-a.png",
  43. text: '购物车',
  44. pagePath: "pages/shoppingCart/shoppingCart"
  45. },
  46. {
  47. id: 4,
  48. selectedIconPath: "../../static/mine-b.png",
  49. iconPath: "../../static/mine-a.png",
  50. text: '我的',
  51. pagePath: "pages/mine/index"
  52. }
  53. ],
  54. };
  55. },
  56. props: {
  57. current: {
  58. type: Number,
  59. default: 0
  60. }
  61. },
  62. mounted() {
  63. const configs = uni.getStorageSync("configs");
  64. console.log("getConfigzj=>", configs);
  65. if (configs) {
  66. this.list[0].selectedIconPath = configs.menu1_on
  67. this.list[0].iconPath = configs.menu1_off
  68. this.list[1].selectedIconPath = configs.menu2_on
  69. this.list[1].iconPath = configs.menu2_off
  70. this.list[2].selectedIconPath = configs.menu3_on
  71. this.list[2].iconPath = configs.menu3_off
  72. this.list[3].selectedIconPath = configs.menu4_on
  73. this.list[3].iconPath = configs.menu4_off
  74. this.list[4].selectedIconPath = configs.menu5_on
  75. this.list[4].iconPath = configs.menu5_off
  76. }
  77. },
  78. methods: {
  79. changeTab(e) {
  80. // 用 switchTab 的前提要在 pages.json中 注册好 tabBar
  81. // 可以把 switchTab换成其他的跳转(比如:navigateTo) 不过好像页面会闪一下,建议switchTab
  82. uni.switchTab({
  83. url: '/' + this.list[e].pagePath,
  84. })
  85. }
  86. }
  87. }
  88. </script>
  89. <style scoped>
  90. .u-page__item__slot-icon {
  91. width: 58rpx !important;
  92. height: 58rpx !important;
  93. }
  94. .u-page__item__slot-icon-index {
  95. width: 58rpx !important;
  96. height: 58rpx !important;
  97. }
  98. </style>