index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. Component({
  2. /**
  3. * 组件的属性列表
  4. */
  5. properties: {},
  6. lifetimes: {
  7. attached() {},
  8. ready: function () {
  9. // 在组件实例进入页面节点树时执行
  10. },
  11. },
  12. /**
  13. * 组件的初始数据
  14. */
  15. /*
  16. {
  17. icon: 'icon-a-biaoqianlangongzuo',
  18. text: '工作',
  19. url: '/pages/tabbar/workbench/index'
  20. }, */
  21. data: {
  22. active: 0,
  23. tabbarList: [{
  24. icon: 'icon-a-biaoqianlanshouyexuanzhong',
  25. text: '首页',
  26. url: '/pages/tabbar/home/index'
  27. },
  28. {
  29. icon: 'icon-a-biaoqianlanxiaoxi',
  30. text: '信息',
  31. url: '/pages/tabbar/message/index'
  32. },
  33. {
  34. icon: 'icon-a-biaoqianlanzhiku',
  35. text: '智库',
  36. url: '/pages/tabbar/smartStore/index',
  37. },
  38. {
  39. icon: 'icon-a-biaoqianlanwode',
  40. text: '我的',
  41. url: '/pages/tabbar/mine/index'
  42. }
  43. ],
  44. },
  45. /**
  46. * 组件的方法列表
  47. */
  48. methods: {
  49. /* tabbar */
  50. onChange(event) {
  51. this.setData({
  52. active: event.target.dataset.index
  53. });
  54. wx.switchTab({
  55. url: event.target.dataset.url
  56. });
  57. },
  58. init() {
  59. const page = getCurrentPages().pop();
  60. this.setData({
  61. active: this.data.tabbarList.findIndex(item => item.url === `/${page.route}`)
  62. });
  63. },
  64. },
  65. })