当前位置:   article > 正文

uni-app uView自定义底部导航栏_uview自定义导航栏遮挡下面元素

uview自定义导航栏遮挡下面元素

因项目需要自定义底部导航栏,我把它写在了组件里,基于uView2框架写的(vue2);

一、代码

 在components下创建tabbar.vue文件,代码如下:

  1. <template>
  2. <view>
  3. <u-tabbar :value="current?current:0" @change="changeTab" :fixed="true" :placeholder="false"
  4. :safeAreaInsetBottom="true" :border="false" activeColor="#40c6a2" inactiveColor="#B9BCBF">
  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.selectedIconPath"></image>
  7. <image class="u-page__item__slot-icon" slot="inactive-icon" :src="item.iconPath"></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. data() {
  19. return {
  20. list: [{
  21. iconPath: "/static/images/salesRecords.png",
  22. selectedIconPath: "/static/images/salesRecords_a.png",
  23. pagePath: "pages/salesRecords/index",
  24. text: "销售记录",
  25. customIcon: false,
  26. }, {
  27. iconPath: "/static/images/mine.png",
  28. selectedIconPath: "/static/images/mine_a.png",
  29. pagePath: "pages/mine/index",
  30. text: "个人中心",
  31. customIcon: false,
  32. }],
  33. }
  34. },
  35. methods: {
  36. // 跳转页面
  37. changeTab(e) {
  38. uni.switchTab({
  39. url: '/' + this.list[e].pagePath,
  40. })
  41. }
  42. }
  43. }
  44. </script>

 app.vue(有没有大佬知道为什么这个样式加载app.vue里才生效)

  1. /* 导航样式 */
  2. .u-tabbar__content {
  3. box-shadow: 0rpx 0rpx 10rpx 2rpx rgba(180, 203, 199, 0.4);
  4. }
  5. .u-page__item__slot-icon {
  6. width: 40rpx;
  7. height: 40rpx;
  8. }

二、配置

 pages.json配置

  1. "tabBar": {
  2. "custom": true,
  3. "list": [
  4. {
  5. "pagePath": "pages/salesRecords/index"
  6. },
  7. {
  8. "pagePath": "pages/mine/index"
  9. }
  10. ]
  11. },

三、使用

页面使用:mine.vue

注:current是底部导航栏的下标,你在tabbar页面的list中写的页面下标从0开始依次递增(如:我这个mine.vue的下标是1,在页面里引用组件时要加上:current="1"

有不懂的可以留言...

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

闽ICP备14008679号