Component({ options: { addGlobalClass: true }, data: { active: 0, list: [ { pagePath: '/pages/index/index', text: '首页', icon: 'home-o', activeIcon: 'wap-home' }, { pagePath: '/pages/category/category', text: '分类', icon: 'apps-o', activeIcon: 'apps-o' }, { pagePath: '/pages/mine/mine', text: '我的', icon: 'user-o', activeIcon: 'manager' } ] }, methods: { onChange(e) { const index = e.detail; const item = this.data.list[index]; wx.switchTab({ url: item.pagePath }); }, init() { const page = getCurrentPages().pop(); const route = page ? `/${page.route}` : ''; const active = this.data.list.findIndex(item => item.pagePath === route); if (active !== -1) { this.setData({ active }); } } } });