当前位置:   article > 正文

uView自定义底部tabbar_uview tabbar

uview tabbar

1.根目录下的static文件夹放入自定义图标

 2.根目录下的components文件夹创建tabbar.vue(注意created要隐藏原生tabbar)

  1. <template>
  2. <view>
  3. <u-tabbar :value="current?current:0" @change="changeTab" :fixed="true" :placeholder="false"
  4. :safeAreaInsetBottom="true" :border="false">
  5. <u-tabbar-item v-for="(item,index) in list" :key="index" :text="item.text">
  6. <image class="u-page__item__slot-icon" slot="active-icon" :src="item.iconPath"></image>
  7. <image class="u-page__item__slot-icon" slot="inactive-icon" :src="item.selectedIconPath"></image>
  8. </u-tabbar-item>
  9. </u-tabbar>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. name: "tabbar",
  15. props: {
  16. current: Number
  17. },
  18. created() {
  19. //隐藏原生tabbar
  20. uni.hideTabBar()
  21. },
  22. data() {
  23. return {
  24. list: [{
  25. selectedIconPath: "../../static/images/tabbar/install.png",
  26. iconPath: "../../static/images/tabbar/install-active.png",
  27. text: '安装单',
  28. customIcon: false,
  29. pagePath: "pages/install/index"
  30. },
  31. {
  32. selectedIconPath: "../../static/images/tabbar/repair.png",
  33. iconPath: "../../static/images/tabbar/repair-active.png",
  34. text: '维修单',
  35. customIcon: false,
  36. pagePath: "pages/repair/index"
  37. },
  38. {
  39. selectedIconPath: "../../static/images/tabbar/my.png",
  40. iconPath: "../../static/images/tabbar/my-active.png",
  41. text: '我的',
  42. customIcon: false,
  43. pagePath: "pages/my/index"
  44. }
  45. ],
  46. }
  47. },
  48. methods: {
  49. changeTab(e) {
  50. console.log(e)
  51. uni.switchTab({
  52. url: '/' + this.list[e].pagePath,
  53. })
  54. }
  55. }
  56. }
  57. </script>
  58. <style scoped>
  59. .u-page__item__slot-icon{
  60. width: 20px!important;
  61. height: 20px!important;
  62. }
  63. </style>

3.main.js全局引用自定义tabbar组件

  1. import tabbar from './components/tabbar/tabbar'
  2. Vue.use('tab-bar',tabbar)

 4.配置pages.json

  1. "tabBar": {
  2. "custom": true,
  3. "list": [
  4. {
  5. "pagePath": "pages/install/index"
  6. },
  7. {
  8. "pagePath": "pages/repair/index"
  9. },
  10. {
  11. "pagePath": "pages/my/index"
  12. }
  13. ]
  14. }

 5.在页面中使用

  1. <template>
  2. <view>
  3. <tabbar :current="0"></tabbar>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. name: "index"
  9. }
  10. </script>
  11. <style scoped>
  12. </style>

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