const app = getApp() Component({ /** * 组件的属性列表 */ properties: {}, /** * 组件的初始数据 */ data: { active: 'pages/home/home', list: app.globalData.tabBarList }, lifetimes: { attached() { this.setData({ list: app.globalData.tabBarList }) app.addTabBarList = res => { this.setData({ list: res }) } } }, /** * 组件的方法列表 */ methods: { onChange(e) { const detail = e.detail const page = getCurrentPages() if (page[page.length - 1].route !== detail) { wx.switchTab({ url: `/${detail}` }) if (detail === 'pages/mine/mine') { app.fetchUserData() } } this.setData({ active: detail }) }, init() { const page = getCurrentPages().pop() this.setData({ active: `${page.route}` }) } } })