index.js 986 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. this.triggerEvent('getTabBarList', res)
  23. })
  24. }
  25. },
  26. /**
  27. * 组件的方法列表
  28. */
  29. methods: {
  30. onChange(e) {
  31. const detail = e.detail
  32. const page = getCurrentPages()
  33. if (page[page.length - 1].route !== detail) {
  34. wx.switchTab({
  35. url: `/${detail}`
  36. })
  37. if (detail === 'pages/mine/mine') {
  38. app.fetchUserData()
  39. }
  40. }
  41. this.setData({
  42. active: detail
  43. })
  44. },
  45. init() {
  46. const page = getCurrentPages().pop()
  47. this.setData({
  48. active: `${page.route}`
  49. })
  50. }
  51. }
  52. })