这个是custom-tab-bar,里面的index文件 [代码]import tabBarData from [代码][代码]'../config/tabBarData.js'[代码][代码];[代码][代码]import style from [代码][代码]'../config/style.js'[代码][代码];[代码][代码]Component({[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]selected: 0,[代码][代码] [代码][代码]backgroundColor: [代码][代码]"#ffffff"[代码][代码],[代码][代码] [代码][代码]borderColor: [代码][代码]"#efefef"[代码][代码],[代码][代码] [代码][代码]color: style.textColor,[代码][代码] [代码][代码]selectedColor: style.mainColor,[代码][代码] [代码][代码]list: [[代码][代码] [代码][代码]{[代码][代码] [代码][代码]pagePath: [代码][代码]"/index/text1/text1"[代码][代码],[代码][代码] [代码][代码]text: [代码][代码]"text1"[代码][代码],[代码][代码] [代码][代码]iconPath: [代码][代码]"/icons/news.png"[代码][代码],[代码][代码] [代码][代码]selectedIconPath: [代码][代码]"/icons/news_active.png"[代码][代码] [代码][代码]},[代码][代码] [代码][代码]{[代码][代码] [代码][代码]pagePath: [代码][代码]"/index/text2/text2"[代码][代码],[代码][代码] [代码][代码]text: [代码][代码]"text2"[代码][代码],[代码][代码] [代码][代码]iconPath: [代码][代码]"/icons/sport.png"[代码][代码],[代码][代码] [代码][代码]selectedIconPath: [代码][代码]"/icons/sport_active.png"[代码][代码] [代码][代码]},[代码][代码] [代码][代码]{[代码][代码] [代码][代码]pagePath: [代码][代码]"/index/text3/text3"[代码][代码],[代码][代码] [代码][代码]text: [代码][代码]"text3"[代码][代码],[代码][代码] [代码][代码]iconPath: [代码][代码]"/icons/target.png"[代码][代码],[代码][代码] [代码][代码]selectedIconPath: [代码][代码]"/icons/target_active.png"[代码][代码] [代码][代码]}[代码][代码] [代码][代码]][代码][代码] [代码][代码]},[代码][代码] [代码][代码]attached() { },[代码][代码] [代码][代码]ready: [代码][代码]function[代码][代码](){[代码][代码] [代码][代码]console.log([代码][代码]'ready'[代码][代码]);[代码][代码] [代码][代码]},[代码][代码] [代码][代码]methods: {[代码][代码] [代码][代码]switchTab(e) {[代码][代码] [代码][代码]const data = e.currentTarget.dataset;[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]selected: data.index[代码][代码] [代码][代码]})[代码][代码] [代码][代码]wx.switchTab({ [代码][代码] [代码][代码]url: data.path[代码][代码] [代码][代码]});[代码][代码] [代码][代码]},[代码][代码] [代码][代码]setTabBarItem(obj) {[代码][代码] [代码][代码]let list = [代码][代码]this[代码][代码].data.list;[代码][代码] [代码][代码]let index = obj.index;[代码][代码] [代码][代码]delete[代码] [代码]obj.index; [代码][代码] [代码][代码]list[index] = Object.assign({},list[index],obj);[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]list: list[代码][代码] [代码][代码]});[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码]})[代码] 这个是页面里面的js文件 [代码]Page({[代码] [代码] onLoad: [代码][代码]function[代码][代码](options) {[代码] [代码] [代码][代码]if[代码] [代码]([代码][代码]typeof[代码] [代码]this[代码][代码].getTabBar === [代码][代码]'function'[代码] [代码]&&[代码][代码] [代码][代码]this[代码][代码].getTabBar()) {[代码][代码] [代码][代码]this[代码][代码].getTabBar().setData({[代码][代码] [代码][代码]selected: 2[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码]})页面编译之后,第一次点击tabBar,tabBar里面的ready会被执行两次,然后导航栏会闪一下
自定义底部导航栏,第一次点击导航按钮时导航会闪烁一下,如何解决?在自定义custom-tab-bar时,当编译之后,第一次点击切换tab时,tabbar会闪烁。给tabbar添加ready方法,发现第一次点击导航按钮时ready会被执行两次,从而导致tabbar闪烁,这应该如何解决?
2019-07-31