custom-tab-bar.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <view>
  3. <u-tabbar :value="activeValue" @change="changeTabbar" zIndex="999" :fixed="true" activeColor="#E96737" :placeholder="true"
  4. :safeAreaInsetBottom="true">
  5. <u-tabbar-item :text="item.text" :name="item.name" v-for="(item, index) in list" :key="index">
  6. <image class="icon" slot="active-icon" :src="item.selectedIconPath"></image>
  7. <image class="icon" slot="inactive-icon" :src="item.iconPath"></image>
  8. </u-tabbar-item>
  9. </u-tabbar>
  10. </view>
  11. </template>
  12. <script>
  13. const app = getApp()
  14. export default {
  15. name: "custom-tab-bar",
  16. props: {
  17. activeValue: {
  18. type: [Number, String],
  19. default: 'index'
  20. },
  21. },
  22. data() {
  23. return {
  24. list: []
  25. };
  26. },
  27. mounted() {
  28. this.tabList()
  29. },
  30. methods: {
  31. changeTabbar(e) {
  32. if (e == 'index') {
  33. uni.switchTab({
  34. url: '/pages/index/index'
  35. })
  36. } else if (e == 'core') {
  37. uni.switchTab({
  38. url: '/pages/core/index'
  39. })
  40. } else if (e == 'activity') {
  41. uni.switchTab({
  42. url: '/pages/activity/index'
  43. })
  44. } else if (e == 'user') {
  45. uni.switchTab({
  46. url: '/pages/user/index'
  47. })
  48. }
  49. },
  50. tabList() {
  51. this.list = [{
  52. name: "index",
  53. iconPath: "../../static/tabbar/index.png",
  54. selectedIconPath: "../../static/tabbar/index_select.png",
  55. text: "刮奖"
  56. },
  57. {
  58. name: "core",
  59. iconPath: "../../static/tabbar/core.png",
  60. selectedIconPath: "../../static/tabbar/core_select.png",
  61. text: "兑换大厅"
  62. },
  63. {
  64. name: "activity",
  65. iconPath: "../../static/tabbar/core.png",
  66. selectedIconPath: "../../static/tabbar/core_select.png",
  67. text: "免费抽奖"
  68. },
  69. {
  70. name: "user",
  71. iconPath: "../../static/tabbar/user.png",
  72. selectedIconPath: "../../static/tabbar/user_select.png",
  73. text: "我的"
  74. }
  75. ]
  76. },
  77. }
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. .icon {
  82. width: 45rpx;
  83. height: 45rpx;
  84. }
  85. </style>