tabbar.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <view class="tabbar">
  3. <u-tabbar
  4. :value="tabbarValue"
  5. @change="tabbarChange"
  6. :fixed="true"
  7. :placeholder="true"
  8. :border="false"
  9. inactiveColor="#999"
  10. activeColor="#009AEF"
  11. :customStyle="{'padding-top':'5px'}"
  12. :safeAreaInsetBottom="true"
  13. >
  14. <u-tabbar-item text="首页" >
  15. <image
  16. class="u-page__item__slot-icon"
  17. slot="active-icon"
  18. src="../static/img/tabbar-home.png"
  19. ></image>
  20. <image
  21. class="u-page__item__slot-icon"
  22. slot="inactive-icon"
  23. src="../static/img/tabbar-home-gray.png"
  24. ></image>
  25. </u-tabbar-item>
  26. <!-- <u-tabbar-item text="奖品兑换" >
  27. <image
  28. class="u-page__item__slot-icon"
  29. slot="active-icon"
  30. src="../static/img/tabbar-gift.png"
  31. ></image>
  32. <image
  33. class="u-page__item__slot-icon"
  34. slot="inactive-icon"
  35. src="../static/img/tabbar-gift-gray.png"
  36. ></image>
  37. </u-tabbar-item> -->
  38. <u-tabbar-item text="个人中心" >
  39. <image
  40. class="u-page__item__slot-icon"
  41. slot="active-icon"
  42. src="../static/img/tabbar-my.png"
  43. ></image>
  44. <image
  45. class="u-page__item__slot-icon"
  46. slot="inactive-icon"
  47. src="../static/img/tabbar-my-gray.png"
  48. ></image>
  49. </u-tabbar-item>
  50. </u-tabbar>
  51. </view>
  52. </template>
  53. <script>
  54. export default {
  55. name: 'tabbar',
  56. props:{
  57. tabbarIndexProps:{
  58. type:Number,
  59. default:0
  60. },
  61. },
  62. data() {
  63. return {
  64. staticUrl:this.$commonConfig.staticUrl,
  65. tabbarValue:0,
  66. }
  67. },
  68. watch:{
  69. 'tabbarIndexProps': {
  70. handler(newVal, oldVal) {
  71. // let pages = getCurrentPages();
  72. // console.log('pages============',pages);
  73. this.tabbarValue = newVal
  74. },
  75. immediate: true
  76. }
  77. },
  78. onLoad() {
  79. console.log('onLoad tabbarIndex',this.tabbarIndex);
  80. },
  81. onShow() {
  82. console.log('tabbarIndex',this.tabbarIndex);
  83. this.tabbarValue = this.tabbarIndex
  84. },
  85. methods: {
  86. tabbarChange(name){
  87. // console.log('name====',name);
  88. const tabBarRoutes = {
  89. 0: '/pages/index/index',
  90. // 1: {
  91. // url: '/shopping/producTypetList',
  92. // query: {
  93. // navType: 'navigateTo'
  94. // }
  95. // },
  96. // 1: '/shopping/order',
  97. 1: '/center/center'
  98. };
  99. const targetRoute = tabBarRoutes[name];
  100. if (typeof targetRoute === 'string') {
  101. uni.reLaunch({url: targetRoute});
  102. } else if (typeof targetRoute === 'object') {
  103. if(targetRoute.query.navType=='navigateTo'){
  104. this.$u.route(targetRoute.url, targetRoute.query);
  105. return
  106. }
  107. let queryParams = uni.$u.queryParams(targetRoute.query);
  108. uni.reLaunch({url: targetRoute.url+queryParams});
  109. }
  110. // this.tabbarValue = name
  111. }
  112. }
  113. }
  114. </script>
  115. <style lang="scss" scoped>
  116. .u-page__item__slot-icon{
  117. width: 40rpx;
  118. height: 40rpx;
  119. &.big{
  120. transform: scale(1.5) translateY(-0.5em);
  121. }
  122. }
  123. </style>