微信程序 自定义遮罩层遮不住底部tabbar解决

一、先上效果

二 方法

1、自定义底部tabbar

实现:

https://developers.weixin.qq.com/miniprogram/dev/framework/ability/custom-tabbar.html 官网去抄

简单写下:在代码根目录下添加入口文件 除了js 文件的list 需要调整 其他原封不动

代码:

js部分

js 复制代码
Component({
  data: {
    selected: 0,
    color: "#7A7E83",
    selectedColor: "#0081FF",
    list: [{  // 同app.json下的tabbar列表
        "iconPath": "/assets/img/build.png",
        "selectedIconPath": "/assets/img/buildSelect.png",
        "pagePath": "/pages/index/index",
        "text": "淘楼"
      },
      {
        "iconPath": "/assets/img/my.png",
        "selectedIconPath": "/assets/img/selectMy.png",
        "pagePath": "/pages/my/index",
        "text": "我的"
      }
    ]
  },
  attached() {},
  methods: {
    switchTab(e) {
      console.log(e.currentTarget)
      const data = e.currentTarget.dataset
      const url = data.path
      wx.switchTab({
        url
      })
      this.setData({
        selected: data.index
      })
    }
  }
})

json

json 复制代码
{
  "component": true,
  "usingComponents": {}
}

wxml

html 复制代码
<!--miniprogram/custom-tab-bar/index.wxml-->
<view class="tab-bar">
  <view class="tab-bar-border"></view>
  <view wx:for="{{list}}" wx:key="index" class="tab-bar-item" data-path="{{item.pagePath}}" data-index="{{index}}" bindtap="switchTab">
    <image src="{{selected === index ? item.selectedIconPath : item.iconPath}}"></image>
    <view style="color: {{selected === index ? selectedColor : color}}">{{item.text}}</view>
  </view>
</view>

wxss

.tab-bar 复制代码
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: white;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 99;
}

.tab-bar-border {
  background-color: rgba(0, 0, 0, 0.33);
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 1px;
  transform: scaleY(0.5);
}

.tab-bar-item {
  flex: 1;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.tab-bar-item image {
  width: 27px;
  height: 27px;
}

.tab-bar-item view {
  font-size: 10px;
}

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: white;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 99;
}

.tab-bar-border {
  background-color: rgba(0, 0, 0, 0.33);
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 1px;
  transform: scaleY(0.5);
}

.tab-bar-item {
  flex: 1;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.tab-bar-item image {
  width: 27px;
  height: 27px;
}

.tab-bar-item view {
  font-size: 10px;
}

2、 list 的中的页面 都需要在onShow中加入一下方法

js 复制代码
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 0
      })
    }

三、遮罩层 盖住底部tabbar 自己实现一个遮罩层或者使用组件 我这儿用的组件 只需要让z-index:的值大于99999 即可

html 复制代码
<!-- 遮罩层 -->
<van-overlay show="{{ overlayShow }}" vertical z-index="{{999999}}">
  <view class="overlay-content">
    <van-loading type="spinner">加载中...</van-loading>
  </view>
</van-overlay>
相关推荐
陈思杰系统思考Jason3 天前
系统思考:自由职业背后的悖论
百度·微信·微信公众平台·新浪微博·微信开放平台
陈思杰系统思考Jason4 天前
系统思考:动态性复杂时代的组织认识
百度·微信·微信公众平台·新浪微博·微信开放平台
WX:ywyy67984 天前
从0到1:付费短剧小程序全栈定制开发实战与避坑指南
微信·小程序·短剧小程序开发·短剧系统开发·短剧app开发·短剧平台开发·短剧平台搭建
陈思杰系统思考Jason6 天前
系统思考:战略定力与组织能力
百度·微信·微信公众平台·新浪微博·微信开放平台
陈思杰系统思考Jason7 天前
系统思考:组织能力持续学习
百度·微信·微信公众平台·新浪微博·微信开放平台
陈思杰系统思考Jason9 天前
系统思考:创办人心智模式与企业规模
百度·微信·微信公众平台·新浪微博·微信开放平台
DokiDoki之父10 天前
边写软件边学kotlin(二)——语法推进
开发语言·微信·kotlin
陈思杰系统思考Jason12 天前
系统思考:心智模式与组织结构
百度·微信·微信公众平台·新浪微博·微信开放平台
陈思杰系统思考Jason14 天前
系统思考:认知边界与组织发展
百度·微信·微信公众平台·新浪微博·微信开放平台
CaracalTiger14 天前
OpenClaw开源项目汇总:Installer一键部署、Moltworker云端方案、钉钉飞书微信接入全指南
微信·开源·aigc·钉钉·飞书·学习方法·业界资讯