小程序自定义tabbar,中间凸起

微信小程序自带tabbar,但无法实现中间按钮凸起样式和功能,因此按照设计重新自定义一个tabbar

1、创建tabbar文件,与pages同级创建一个文件夹,custom-tab-bar,里面按照设计图将底部tabbar样式编写

csharp 复制代码
<view class="tab-bar">
  <view class="tab-bar-border"></view>
  <block wx:for="{{list}}" wx:key="index">
    <view wx:if="{{item.isSpecial}}" class="tab-bar-item" data-name="{{item.text}}" data-path="{{item.pagePath}}" data-click="{{ item.isSpecial || false }}" data-index="{{index}}" bindtap="switchTab">
      <view class="special-image">
        <image class="special-image-pic" mode="widthFix" src="{{selected === index ? item.selectedIconPath : item.iconPath}}"></image>
      </view>
      <view style="color: {{selected === index ? selectedColor : color}}" class="special-text tab-text">{{item.text}}</view>
      
    </view>
    <view wx:else class="tab-bar-item" data-name="{{item.text}}" data-path="{{item.pagePath}}" data-click="{{ item.isSpecial }}" data-index="{{index}}" bindtap="switchTab">
      <image class="item-image" mode="widthFix" src="{{selected === index ? item.selectedIconPath : item.iconPath}}"></image>
      <view class="tab-text" style="color: {{selected === index ? selectedColor : color}}">{{item.text}}</view>
      <view class="num" wx:if="{{item.text == '消息' && message_num != 0}}">{{message_num}}</view>
    </view>
  </block>
</view>

2、在app.js中添加点击事件

csharp 复制代码
  /* 自定义底部按钮切换 */
  getCurrentTabbar(selected, that) {
    if (typeof that.getTabBar === 'function' &&
      that.getTabBar()) {
      if (wx.getStorageSync('openid')) {
        msg_unread().then(res => {
          that.getTabBar().setData({
            selected: selected,
            message_num: res.data.data
          })
        })
      } else {
        that.getTabBar().setData({
          selected: selected
        })
      }
    }
  },

3、在app.json中修改默认tabbar数据结构

csharp 复制代码
  "tabBar": {
    "custom": true,
    "list": [
        {
            "pagePath": "pages/index/index",
            "text": "首页"
        },
        {
            "pagePath": "pages/contact/index",
            "text": "通讯录"
        },
        {
            "pagePath": "pages/release/index",
            "text": "发布"
        },
        {
            "pagePath": "pages/news/index",
            "text": "消息"
        },
        {
            "pagePath": "pages/personal/index",
            "text": "我的"
        }
    ]
},

4、在对应的页面中执行点击事件

csharp 复制代码
  app.getCurrentTabbar(index,this);
  /* index:tabbar对应的index */

如需源码,请点击下载源码,或点击顶部下载按钮

相关推荐
guanpinkeji6 小时前
卡牌抽卡机小程序:市场发展下的创新
小程序·团队开发·小程序开发·抽卡机·抽卡机小程序·卡牌·卡牌小程序
I592O9297836 小时前
二二复制模式小程序商城开发
小程序
工业互联网专业9 小时前
毕业设计选题:基于ssm+vue+uniapp的捷邻小程序
vue.js·小程序·uni-app·毕业设计·ssm·源码·课程设计
战神刘玉栋12 小时前
《微信小程序实战(2) · 组件封装》
微信小程序·小程序·notepad++
李宥小哥16 小时前
微信小程序04-常用API上
微信小程序·小程序·notepad++
程序员阿龙16 小时前
计算机毕业设计之:教学平台微信小程序(
微信小程序·小程序·课程设计·在线教育·教育管理系统·个性化教学·学习进度跟踪
Jiaberrr17 小时前
教你如何在微信小程序中轻松实现人脸识别功能
javascript·微信小程序·小程序·人脸识别·百度ai
说私域17 小时前
开源 AI 智能名片 S2B2C 商城小程序与正能量融入对社群归属感的影响
人工智能·小程序
I592O9297831 天前
CRM客户关系管理系统开发源码小程序
小程序
h177113472051 天前
单身狗的逆袭之路之开发相亲交友系统
微信小程序·小程序·交友·系统开发·回归算法