首先先看官网:https://developers.weixin.qq.com/miniprogram/dev/framework/ability/custom-tabbar.html
详细官方都有介绍,下面具体介绍用法:
在tabBar组件的indexjs里:
switchTab(e) { const data = e.currentTarget.dataset const url = data.path console.log(data.index,url,this.getTabBar()) wx.switchTab({url}) app.globalData.tabBarIndex = data.index; /* 然后到每个tabBar页面的onshow方法里调用一下代码 if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ tabBarIndex: app.globalData.tabBarIndex }) } */ }