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