index.js 921 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const app = getApp()
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {},
  7. /**
  8. * 组件的初始数据
  9. */
  10. data: {
  11. active: 'pages/home/home',
  12. list: app.globalData.tabBarList
  13. },
  14. attached() {
  15. this.setData({
  16. list: app.globalData.tabBarList
  17. })
  18. app.addTabBarList = res => {
  19. this.setData({
  20. list: res
  21. })
  22. }
  23. },
  24. /**
  25. * 组件的方法列表
  26. */
  27. methods: {
  28. onChange(e) {
  29. const detail = e.detail
  30. const page = getCurrentPages()
  31. if (page[page.length - 1].route !== detail) {
  32. wx.switchTab({
  33. url: `/${detail}`
  34. })
  35. if (detail === 'pages/mine/mine') {
  36. app.fetchUserData()
  37. }
  38. }
  39. this.setData({
  40. active: detail
  41. })
  42. },
  43. init() {
  44. const page = getCurrentPages().pop()
  45. this.setData({
  46. active: `${page.route}`
  47. })
  48. }
  49. }
  50. })