// components/custom-tabbar/custom-tabbar.js Component({ data: { selected: 0, color: "#666666", selectedColor: "#667eea", list: [ { pagePath: "/pages/index/index", text: "打牌记账", iconPath: "../images/index.png", selectedIconPath: "../images/index_active.png" }, { pagePath: "/pages/stats/personal/personal", text: "统计分析", iconPath: "../images/record.png", selectedIconPath: "../images/record-active.png" }, { pagePath: "/pages/profile/index/index", text: "我的", iconPath: "../images/my.png", selectedIconPath: "../images/my-active.png" } ] }, properties: { selected: { type: Number, value: 0 } }, lifetimes: { attached() { // 组件初始化时更新选中状态 this.setData({ selected: this.data.selected }) } }, methods: { switchTab(e) { const index = e.currentTarget.dataset.index const pagePath = this.data.list[index].pagePath // 触发事件通知父组件 this.triggerEvent('tabchange', { index, pagePath }) // 切换页面 wx.switchTab({ url: pagePath }) } } })