微信小程序custom-tab-bar

微信小程序自定义tab-bar。

tab-bar使用tdesign中的t-tab-bar

1 在项目下新建custom-tab-bar文件夹,新建index 组件。

1.1 index.wxml中增加t-tab-bar

wxml 复制代码
<t-tab-bar value="{{value}}"    bindchange="onChange" theme="tag" split="{{false}}">
  <t-tab-bar-item wx:for="{{list}}" wx:key="index"  value="{{item.value}}"   icon="{{item.icon}}">
    {{item.label}}
  </t-tab-bar-item>
</t-tab-bar>

1.2在index.js中增加以下代码

js 复制代码
 
Component({
    data: {
      value: 0,  
      list: [
        {value:0, pagePath: 'pages/home/index', label: '首页', icon: 'home' },
        {value:1, pagePath: 'pages/person-center/index', label: '个人中心', icon: 'user' }
      ],
    },
  
    methods: {
        init(){
            const page = getCurrentPages().pop();
            let a=this.data.list.find(item=>item.pagePath === page.route)
            this.setData({
                value:a.value
            });
          },
      onChange(e) {
            this.setData({
                value: e.detail.value
            });
            wx.switchTab({
                url: '/' + this.data.list[e.detail.value].pagePath
              });           
        }
    },
  });
  

2在app.json中配置tab

json 复制代码
"tabBar": {
        "selectedColor": "#33a3dc",
        "backgroundColor": "#ffffff",
        "color": "#000000",
        "custom": true,
        "list": [
            {
                "text": "首页",
                "pagePath": "pages/home/index"
            },
            {
                "text": "个人中心",
                "pagePath": "pages/person-center/index"
            }
        ]
    },
    "usingComponents": {
        "t-tab-bar": "tdesign-miniprogram/tab-bar/tab-bar",
        "t-tab-bar-item": "tdesign-miniprogram/tab-bar-item/tab-bar-item"
	}

3.在pages/home/index.js和pages/person-center/index.js中加入如下代码

js 复制代码
onShow() {
        this.getTabBar().init();
    },

编译后即可实现自定义tab-bar。

相关推荐
数字游民952720 小时前
推荐一个自带流量加成的小程序接口
人工智能·ai·小程序
2501_9159090621 小时前
Charles 抓不到包怎么办?iOS 调试过程中如何判断请求路径
android·ios·小程序·https·uni-app·iphone·webview
2501_9160074721 小时前
iOS和iPadOS文件管理系统全面解析与使用指南
android·ios·小程序·https·uni-app·iphone·webview
2501_915921431 天前
iOS App 开发阶段性能优化,观察 CPU、内存和日志变化
android·ios·性能优化·小程序·uni-app·iphone·webview
qq_12498707531 天前
基于微信小程序的垃圾分类信息系统(源码+论文+部署+安装)
java·前端·spring boot·后端·微信小程序·小程序·计算机毕业设计
qq_12498707531 天前
基于微信小程序的照片社交平台(源码+论文+部署+安装)
java·大数据·微信小程序·小程序·毕业设计·计算机毕业设计
Focussend智能化营销1 天前
【无标题】重构增长链路:如何将企业小程序从“成本中心”,改造为“利润中心”?
人工智能·小程序·重构·自动化·内容运营·数字化营销
游戏开发爱好者81 天前
在 iOS 开发、测试与上架过程中 如何做证书管理
android·ios·小程序·https·uni-app·iphone·webview
计算机毕设指导61 天前
基于微信小程序的健康管理系统【源码文末联系】
java·spring boot·微信小程序·小程序·tomcat·maven·intellij-idea
计算机毕设指导61 天前
基于微信小程序的电影评论与推荐社区平台【源码文末联系】
java·spring boot·微信小程序·小程序·tomcat·maven·intellij-idea