index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // custom-tab-bar/index.js
  2. Component({
  3. data: {
  4. selected: 0, // 当前选中的 tab 索引
  5. color: "#999999",
  6. selectedColor: "#F7393F",
  7. list: [
  8. {
  9. text: "首页",
  10. pagePath: "/pages/Home/Home",
  11. iconPath: "/assets/taddar/首页.png",
  12. selectedIconPath: "/assets/taddar/首页 (1).png"
  13. },
  14. {
  15. text: "反酸模型",
  16. pagePath: "/pages/Soil Acidification/Soil Acidification",
  17. iconPath: "/assets/taddar/chart-histogram (1).png",
  18. selectedIconPath: "/assets/taddar/chart-histogram.png"
  19. },
  20. {
  21. text: "降酸模型",
  22. pagePath: "/pages/Soil Deacidification/Soil Deacidification",
  23. iconPath: "/assets/taddar/Data_Visualization-active.png",
  24. selectedIconPath: "/assets/taddar/Data_Visualization.png"
  25. },
  26. {
  27. text: "人员中心",
  28. pagePath: "/pages/Staff/Staff",
  29. iconPath: "/assets/taddar/users-copy.png",
  30. selectedIconPath: "/assets/taddar/copy.png"
  31. }
  32. ]
  33. },
  34. attached() {
  35. // 可在此设置初始选中项
  36. },
  37. methods: {
  38. switchTab(e) {
  39. const { index, path } = e.currentTarget.dataset;
  40. wx.switchTab({
  41. url: path,
  42. });
  43. this.setData({
  44. selected: index, // 更新当前选中的 tab 索引
  45. });
  46. },
  47. },
  48. });