custom-tab-bar.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <view>
  3. <u-tabbar :value="activeValue" @change="changeTabbar" :fixed="true" :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. console.log(e);
  33. if (e == 'index') {
  34. uni.switchTab({
  35. url: '/pages/index/index'
  36. })
  37. } else if (e == 'core') {
  38. uni.switchTab({
  39. url: '/pages/core/index'
  40. })
  41. } else if (e == 'user') {
  42. uni.switchTab({
  43. url: '/pages/user/index'
  44. })
  45. }
  46. },
  47. tabList() {
  48. this.list = [{
  49. name: "index",
  50. iconPath: "../../static/tabbar/index.png",
  51. selectedIconPath: "../../static/tabbar/index_select.png",
  52. text: "刮奖"
  53. },
  54. {
  55. name: "core",
  56. iconPath: "../../static/tabbar/law.png",
  57. selectedIconPath: "../../static/tabbar/law_select.png",
  58. text: "兑换大厅"
  59. },
  60. {
  61. name: "user",
  62. iconPath: "../../static/tabbar/user.png",
  63. selectedIconPath: "../../static/tabbar/user_select.png",
  64. text: "我的"
  65. }
  66. ]
  67. },
  68. }
  69. }
  70. </script>
  71. <style lang="scss" scoped>
  72. .icon {
  73. width: 54rpx;
  74. height: 54rpx;
  75. }
  76. </style>