index.js 1.1 KB

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