tabbar.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view class="">
  3. <u-tabbar
  4. :value="tabbarValue"
  5. @change="tabbarChange"
  6. :fixed="true"
  7. :placeholder="true"
  8. :border="false"
  9. inactiveColor="#666"
  10. activeColor="#00A447"
  11. :safeAreaInsetBottom="true"
  12. >
  13. <u-tabbar-item text="商城" >
  14. <image
  15. class="u-page__item__slot-icon"
  16. slot="active-icon"
  17. :src="staticUrl+'/img/tabbar-mall.png'"
  18. ></image>
  19. <image
  20. class="u-page__item__slot-icon"
  21. slot="inactive-icon"
  22. :src="staticUrl+'/img/tabbar-mall-gray.png'"
  23. ></image>
  24. </u-tabbar-item>
  25. <u-tabbar-item text="分类" >
  26. <image
  27. class="u-page__item__slot-icon"
  28. slot="active-icon"
  29. :src="staticUrl+'/img/tabbar-classify.png'"
  30. ></image>
  31. <image
  32. class="u-page__item__slot-icon"
  33. slot="inactive-icon"
  34. :src="staticUrl+'/img/tabbar-classify-gray.png'"
  35. ></image>
  36. </u-tabbar-item>
  37. <u-tabbar-item text="关于旭烁" >
  38. <image
  39. class="u-page__item__slot-icon"
  40. slot="active-icon"
  41. :src="staticUrl+'/img/tabbar-xushuo-v2.png'"
  42. ></image>
  43. <image
  44. class="u-page__item__slot-icon"
  45. slot="inactive-icon"
  46. :src="staticUrl+'/img/tabbar-xushuo-v2-gray.png'"
  47. ></image>
  48. </u-tabbar-item>
  49. <!-- <u-tabbar-item text="购物车" >
  50. <image
  51. class="u-page__item__slot-icon"
  52. slot="active-icon"
  53. src="/static/img/tabbar-car.png"
  54. ></image>
  55. <image
  56. class="u-page__item__slot-icon"
  57. slot="inactive-icon"
  58. src="/static/img/tabbar-car-gray.png"
  59. ></image>
  60. </u-tabbar-item> -->
  61. <u-tabbar-item text="我的" >
  62. <image
  63. class="u-page__item__slot-icon"
  64. slot="active-icon"
  65. :src="staticUrl+'/img/tabbar-my.png'"
  66. ></image>
  67. <image
  68. class="u-page__item__slot-icon"
  69. slot="inactive-icon"
  70. :src="staticUrl+'/img/tabbar-my-gray.png'"
  71. ></image>
  72. </u-tabbar-item>
  73. </u-tabbar>
  74. </view>
  75. </template>
  76. <script>
  77. export default {
  78. name: 'tabbar',
  79. props:{
  80. tabbarIndexProps:{
  81. type:Number,
  82. default:0
  83. },
  84. },
  85. data() {
  86. return {
  87. staticUrl:this.$commonConfig.staticUrl,
  88. tabbarValue:0,
  89. }
  90. },
  91. watch:{
  92. 'tabbarIndexProps': {
  93. handler(newVal, oldVal) {
  94. this.tabbarValue = newVal
  95. },
  96. immediate: true
  97. }
  98. },
  99. onLoad() {
  100. console.log('onLoad tabbarIndex',this.tabbarIndex);
  101. },
  102. onShow() {
  103. console.log('tabbarIndex',this.tabbarIndex);
  104. this.tabbarValue = this.tabbarIndex
  105. },
  106. methods: {
  107. tabbarChange(name){
  108. console.log('name====',name);
  109. const tabBarRoutes = {
  110. 0: '/pages/index/index',
  111. 1: {
  112. url: '/shopping/producTypetList',
  113. query: {
  114. type: 'redirect'
  115. }
  116. },
  117. 2: '/xushuo/xushuo',
  118. // 3: '/shopping/cart',
  119. 3: '/center/center'
  120. };
  121. const targetRoute = tabBarRoutes[name];
  122. if (typeof targetRoute === 'string') {
  123. uni.$u.route(targetRoute,{type: 'redirect'});
  124. } else if (typeof targetRoute === 'object') {
  125. uni.$u.route(targetRoute.url, targetRoute.query);
  126. }
  127. // this.tabbarValue = name
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. .u-page__item__slot-icon{
  134. width: 60rpx;
  135. height: 60rpx;
  136. &.big{
  137. transform: scale(1.5) translateY(-0.5em);
  138. }
  139. }
  140. </style>