Component({ options: { addGlobalClass: true }, data: { active: 0, list: [ { pagePath: '/pages/index/index', text: '้ฆ–้กต', icon: 'home-o' }, { pagePath: '/pages/mine/mine', text: 'ๆˆ‘็š„', icon: 'user-o' } ] }, 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 }); } } } });