当前位置:   article > 正文

uniapp实现tabbar中间凸出效果_uniapp底部导航栏中间凸起

uniapp底部导航栏中间凸起

 

1.实现一个自定义的tabbar

1.1在components下创建一个tabbar文件

  1. <view class="tabbar-container">
  2. <view class="tabbar-item" v-for="(item, index) in tabbarList" :class="[item.centerItem ? ' center-item' : '']"
  3. @click="changeItem(item)">
  4. <view class="item-top">
  5. <image :src="currentItem == item.id ? item.selectIcon : item.icon"></image>
  6. </view>
  7. <view class="item-bottom" :class="[currentItem == item.id ? 'item-active' : '']">
  8. <text>{{ item.text }}</text>
  9. </view>
  10. </view>
  11. </view>
  12. <script>
  13. export default {
  14. props: {
  15. currentPage: {
  16. type: Number,
  17. default: 0
  18. }
  19. },
  20. data() {
  21. return {
  22. currentItem: 0,
  23. tabbarList: [{
  24. id: 0,
  25. path: '/pages/tabbar/home/index',
  26. icon: '/static/tabbar/images/home.png',
  27. selectIcon: '/static/tabbar/images/home_select.png',
  28. text: '首页',
  29. centerItem: false
  30. },
  31. {
  32. id: 1,
  33. path: '/pages/tabbar/goods/index',
  34. icon: '/static/tabbar/images/goods.png',
  35. selectIcon: '/static/tabbar/images/home_select.png',
  36. text: '我的订单',
  37. centerItem: false
  38. },
  39. {
  40. id: 2,
  41. path: '/pages/tabbar/vip/vip',
  42. icon: '/static/tabbar/images/vip.png',
  43. selectIcon: '/static/tabbar/images/home_select.png',
  44. text: '成为会员',
  45. centerItem: true
  46. },
  47. {
  48. id: 3,
  49. path: '/pages/tabbar/team/team',
  50. icon: '/static/tabbar/images/team.png',
  51. selectIcon: '/static/tabbar/images/home_select.png',
  52. text: '我的团队',
  53. centerItem: false
  54. },
  55. {
  56. id: 4,
  57. path: '/pages/tabbar/user/user',
  58. icon: '/static/tabbar/images/user.png',
  59. selectIcon: '/static/tabbar/images/user_select.png',
  60. text: '会员中心',
  61. centerItem: false
  62. }
  63. ]
  64. };
  65. },
  66. mounted() {
  67. this.currentItem = this.currentPage;
  68. uni.hideTabBar();
  69. },
  70. methods: {
  71. changeItem(item) {
  72. let _this = this;
  73. _this.currentItem = item.id;
  74. uni.switchTab({
  75. url: item.path
  76. });
  77. }
  78. }
  79. };
  80. </script>

2.pages.js配置——tabbar正常配置

  1. "tabBar": {
  2. "custom": false,//防止二次点击失效
  3. /*颜色*/
  4. "color": "#000000",
  5. /*选中之后的*/
  6. "selectedColor": "#29B2EC",
  7. /*边框*/
  8. "borderStyle": "black",
  9. "backgroundColor": "#f7f7f7",
  10. "midButton": {
  11. "text": "xxx",
  12. "pagePath": "pages/tabbar/vip/vip",
  13. "iconPath": "static/tabbar/images/vip.png",
  14. "selectedIconPath": "static/tabbar/images/vip.png"
  15. },
  16. "list": [{
  17. "iconPath": "static/tabbar/images/home.png",
  18. "selectedIconPath": "static/tabbar/images/home_select.png",
  19. "text": "首页",
  20. "pagePath": "pages/tabbar/home/index"
  21. },
  22. {
  23. /*图标路径*/
  24. "iconPath": "static/tabbar/images/goods.png",
  25. /*点击图片后的路径*/
  26. // "selectedIconPath": "static/tabbar/user_select.png",
  27. /*文本文字*/
  28. "text": "xxx",
  29. /*显示的路径*/
  30. "pagePath": "pages/tabbar/goods/index"
  31. },
  32. {
  33. /*图标路径*/
  34. "iconPath": "static/tabbar/images/vip.png",
  35. /*点击图片后的路径*/
  36. // "selectedIconPath": "static/tabbar/images/user_select.png",
  37. /*文本文字*/
  38. "text": "xxx",
  39. /*显示的路径*/
  40. "pagePath": "pages/tabbar/vip/vip"
  41. },
  42. {
  43. /*图标路径*/
  44. "iconPath": "static/tabbar/images/team.png",
  45. /*点击图片后的路径*/
  46. // "selectedIconPath": "static/tabbar/images/user_select.png",
  47. /*文本文字*/
  48. "text": "xxx",
  49. /*显示的路径*/
  50. "pagePath": "pages/tabbar/team/team"
  51. },
  52. {
  53. /*图标路径*/
  54. "iconPath": "static/tabbar/images/user.png",
  55. /*点击图片后的路径*/
  56. "selectedIconPath": "static/tabbar/images/user_select.png",
  57. /*文本文字*/
  58. "text": "xxx",
  59. /*显示的路径*/
  60. "pagePath": "pages/tabbar/user/user"
  61. }
  62. ]

3.tabbar全局引入,在main.js中引入

  1. import Tabbar from "components/tabbar.vue"
  2. Vue.component('tabbar', Tabbar)

4.tabbar局部引入,在你所需要用到的地方引入

  1. <view class="container">
  2. <tabbar :current-page="0"></tabbar>
  3. </view>
  4. <script>
  5. import tabbar from '@/compenets/tabbar.vue'
  6. export default {
  7. components:{tabbar }
  8. onShow: function() {
  9. //隐藏pages.js配置的tabbar
  10. uni.hideTabBar({
  11. animation: true
  12. })
  13. console.log('App Show')
  14. },
  15. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/113160
推荐阅读
相关标签
  

闽ICP备14008679号