import { getCurrentPageUrl } from '@/utils/util' const app = getApp() Component({ properties: {}, data: { imageUrl: app.globalData.imageUrl, isChild: 0, active: 0, list: [ { pagePath: '/pages/index/index', text: '首页', icon: 'tabbar1-1', iconActive: 'tabbar1-1-active', }, { pagePath: '/pages/repository/index', text: 'MG全知道', icon: 'tabbar1-2', iconActive: 'tabbar1-2-active', }, { pagePath: '/pages/my/index', text: '我的', icon: 'tabbar1-2', iconActive: 'tabbar1-3-active', }, ], }, observers: {}, lifetimes: { ready() { const pagePath = getCurrentPageUrl() const active = this.data.list.findIndex((item) => item.pagePath === pagePath) this.setData({ active, anyWhere: app.globalData.anyWhere, }) }, }, methods: { onChange() {}, handleNav(e) { const { index } = e.currentTarget.dataset const { list } = this.data const pagePath = list[index].pagePath wx.switchTab({ url: pagePath, }) }, }, })