index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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. (0, component_1.VantComponent)({
  6. relation: (0, 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, children = _a.children, currentActive = _a.currentActive;
  22. if (!children.length) {
  23. return Promise.resolve();
  24. }
  25. this.currentActive = activeKey;
  26. var stack = [];
  27. if (currentActive !== activeKey && children[currentActive]) {
  28. stack.push(children[currentActive].setActive(false));
  29. }
  30. if (children[activeKey]) {
  31. stack.push(children[activeKey].setActive(true));
  32. }
  33. return Promise.all(stack);
  34. },
  35. },
  36. });