本文共 2276 字,大约阅读时间需要 7 分钟。
github传送门https://github.com/SuRuiGit/wxapp-customTabbar
//自己对wx.hideTabBar的一个封装hidetabbar() { wx.hideTabBar({ fail: function() { setTimeout(function() { // 做了个延时重试一次,作为保底。 wx.hideTabBar() }, 500) } }); },getSystemInfo: function() { let t = this; wx.getSystemInfo({ success: function(res) { t.globalData.systemInfo = res; } }); },
第四步:在app.js中的globalData中加入自定义tabbar和systemInfo的参数,再加入一个方法给tabBar.list配置中的页面使用,代码如下
editTabbar: function() { let tabbar = this.globalData.tabBar; let currentPages = getCurrentPages(); let _this = currentPages[currentPages.length - 1]; let pagePath = _this.route; (pagePath.indexOf('/') != 0) && (pagePath = '/' + pagePath); for (let i in tabbar.list) { tabbar.list[i].selected = false; (tabbar.list[i].pagePath == pagePath) && (tabbar.list[i].selected = true); } _this.setData({ tabbar: tabbar });},globalData: { systemInfo: null,//客户端设备信息 tabBar: { "backgroundColor": "#ffffff", "color": "#979795", "selectedColor": "#1c1c1b", "list": [ { "pagePath": "/page/index/index", "iconPath": "icon/icon_home.png", "selectedIconPath": "icon/icon_home_HL.png", "text": "首页" }, { "pagePath": "/page/myRelease/index", "iconPath": "icon/icon_release.png", "isSpecial": true, "text": "发布" }, { "pagePath": "/page/mine/index", "iconPath": "icon/icon_mine.png", "selectedIconPath": "icon/icon_mine_HL.png", "text": "我的" } ] }}
第五步:在tabBar的list中配置的页面的.js文件的data中加入tabbar:{},并在onload方法中调用app.editTabbar();
第六步:在tabBar的list中配置的页面的.json文件中加入"usingComponents": { “tabbar”: “…/…/tabbarComponent/tabbar” }在.wxml文件中加入第七步:修改tabbarComponent->tabbar.js->data中的代码,代码截图如下
到此我们就实现了突出效果,首先感谢大佬提供的轮子,如果侵权,请联系我,我会第一时间删除本文章
转载地址:http://vtemz.baihongyu.com/