微信小程序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。

相关推荐
2501_9151063220 小时前
iOS 成品包加固,在只有 IPA 的情况下,能做那些操作
android·ios·小程序·https·uni-app·iphone·webview
滑稽的1 天前
微信小程序过滤功能实现
微信小程序·小程序
2501_915909061 天前
苹果iOS应用上架详细流程与注意事项解析
android·ios·小程序·https·uni-app·iphone·webview
漏刻有时1 天前
微信小程序学习实录15:微信小程序基于百度云人脸识别的刷脸打卡开发方案
学习·微信小程序·百度云
亿坊电商1 天前
【家政服务】小程序+APP(项目源码),三端无缝协同系统解析!
小程序·开源软件
莫桐1 天前
微信小程序-ios环境下webview打开的h5页面replace跳转方式不生效问题
ios·微信小程序·小程序
2501_915909061 天前
在无需越狱的前提下如何对 iOS 设备进行文件管理与数据导出
android·macos·ios·小程序·uni-app·cocoa·iphone
UI设计兰亭妙微1 天前
新东方文旅小程序用户体验界面设计优化
小程序·ux·用户体验设计
说私域1 天前
链动2+1模式AI智能名片小程序赋能客户端微商生态化构建研究
人工智能·小程序·流量运营·私域运营
毕设源码-钟学长1 天前
【开题答辩全过程】以 基于微信小程序的考公论坛的设计与实现为例,包含答辩的问题和答案
微信小程序·小程序