// custom-tab-bar/index.js Component({ data: { rightId:wx.getStorageSync('rightId') || 0, list: [], list1: [ { "pagePath": "../home/home", "text": "首页", "iconPath": "/img/index_unaction.png", "selectedIconPath": "/img/index_action.png" }, { "pagePath": "../me/me", "text": "我的", "iconPath": "/img/me_unaction.png", "selectedIconPath": "/img/me_action.png" } ], list2: [ { "pagePath": "../home/home", "text": "首页", "iconPath": "/img/index_unaction.png", "selectedIconPath": "/img/index_action.png" }, { "pagePath": "../index/index", "text": "频道", "iconPath": "/img/index_unaction.png", "selectedIconPath": "/img/index_action.png" }, { "pagePath": "../me/me", "text": "我的", "iconPath": "/img/me_unaction.png", "selectedIconPath": "/img/me_action.png" } ] }, attached() { this.changeList() getApp().eventBus.on('rightChange', data => { if (data !== this.data.rightId) { this.setData({ rightId: data }) this.changeList() } }) }, detached() { app.eventBus.off('rightChange') }, methods: { changeList() { this.setData({ rightId: wx.getStorageSync('rightId') || 0 }) if (this.data.rightId === 1) { this.setData({ list: this.data.list2 }) } else { this.setData({ list: this.data.list1 }) } }, switchTab(e) { const data = e.currentTarget.dataset const url = data.path wx.switchTab({ url: url, fail:function(e){ console.log("点击切换失败"+ e.errMsg); } }) } } })