custom-tab-bar.vue 1.6 KB

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