tabbar.vue 2.5 KB

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