index.js 625 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. Component({
  2. data: {
  3. active: 0,
  4. list: [
  5. {
  6. icon: 'home-o',
  7. text: '首页',
  8. url: '/pages/index/index'
  9. },
  10. {
  11. icon: 'bar-chart-o',
  12. text: '数据中心',
  13. url: '/pages/data/index'
  14. },
  15. {
  16. icon: 'user-o',
  17. text: '个人中心',
  18. url: '/pages/account/index'
  19. }
  20. ]
  21. },
  22. methods: {
  23. onChange(event) {
  24. this.setData({ active: event.detail });
  25. wx.switchTab({
  26. url: this.data.list[event.detail].url
  27. });
  28. },
  29. init() {
  30. const page = getCurrentPages().pop();
  31. this.setData({
  32. active: this.data.list.findIndex(item => item.url === `/${page.route}`)
  33. });
  34. }
  35. }
  36. });