// custom-tab-bar/index.js Component({ data: { selected: 0, // 当前选中的 tab 索引 color: "#999999", selectedColor: "#F7393F", list: [ { text: "首页", pagePath: "/pages/Home/Home", iconPath: "/assets/taddar/首页.png", selectedIconPath: "/assets/taddar/首页 (1).png" }, { text: "反酸模型", pagePath: "/pages/Soil Acidification/Soil Acidification", iconPath: "/assets/taddar/chart-histogram (1).png", selectedIconPath: "/assets/taddar/chart-histogram.png" }, { text: "降酸模型", pagePath: "/pages/Soil Deacidification/Soil Deacidification", iconPath: "/assets/taddar/Data_Visualization-active.png", selectedIconPath: "/assets/taddar/Data_Visualization.png" }, { text: "人员中心", pagePath: "/pages/Staff/Staff", iconPath: "/assets/taddar/users-copy.png", selectedIconPath: "/assets/taddar/copy.png" } ] }, attached() { // 可在此设置初始选中项 }, methods: { switchTab(e) { const { index, path } = e.currentTarget.dataset; wx.switchTab({ url: path, }); this.setData({ selected: index, // 更新当前选中的 tab 索引 }); }, }, });