index.js 606 Bytes
const { TAB_LIST } = require('~/utils/tabBarConfig')

Component({
  data: {
    selected: 0,
    color: '#999999',
    selectedColor: '#222222',
    list: TAB_LIST,
  },
  lifetimes: {
    attached() {
      TAB_LIST.forEach((item) => {
        wx.getImageInfo({ src: item.iconPath, fail() {} })
        wx.getImageInfo({ src: item.selectedIconPath, fail() {} })
      })
    },
  },
  methods: {
    switchTab(e) {
      const { path, index } = e.currentTarget.dataset
      if (this.data.selected === index) return
      wx.switchTab({ url: path })
      this.setData({ selected: index })
    },
  },
})