index.js 727 B

1234567891011121314151617181920212223242526272829
  1. import TabMenu from './data';
  2. Component({
  3. data: {
  4. active: 0,
  5. list: TabMenu,
  6. },
  7. methods: {
  8. onChange(event) {
  9. this.setData({ active: event.detail.value });
  10. wx.switchTab({
  11. url: this.data.list[event.detail.value].url.startsWith('/')
  12. ? this.data.list[event.detail.value].url
  13. : `/${this.data.list[event.detail.value].url}`,
  14. });
  15. },
  16. init() {
  17. const page = getCurrentPages().pop();
  18. const route = page ? page.route.split('?')[0] : '';
  19. const active = this.data.list.findIndex(
  20. (item) =>
  21. (item.url.startsWith('/') ? item.url.substr(1) : item.url) ===
  22. `${route}`,
  23. );
  24. this.setData({ active });
  25. },
  26. },
  27. });