index.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var component_1 = require('../common/component');
  4. var relation_1 = require('../common/relation');
  5. component_1.VantComponent({
  6. relation: relation_1.useChildren('sidebar-item', function () {
  7. this.setActive(this.data.activeKey);
  8. }),
  9. props: {
  10. activeKey: {
  11. type: Number,
  12. value: 0,
  13. observer: 'setActive',
  14. },
  15. },
  16. beforeCreate: function () {
  17. this.currentActive = -1;
  18. },
  19. methods: {
  20. setActive: function (activeKey) {
  21. var _a = this,
  22. children = _a.children,
  23. currentActive = _a.currentActive;
  24. if (!children.length) {
  25. return Promise.resolve();
  26. }
  27. this.currentActive = activeKey;
  28. var stack = [];
  29. if (currentActive !== activeKey && children[currentActive]) {
  30. stack.push(children[currentActive].setActive(false));
  31. }
  32. if (children[activeKey]) {
  33. stack.push(children[activeKey].setActive(true));
  34. }
  35. return Promise.all(stack);
  36. },
  37. },
  38. });