index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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, children = _a.children, currentActive = _a.currentActive;
  29. if (!children.length) {
  30. return Promise.resolve();
  31. }
  32. this.currentActive = activeKey;
  33. var stack = [];
  34. if (currentActive !== activeKey && children[currentActive]) {
  35. stack.push(children[currentActive].setActive(false));
  36. }
  37. if (children[activeKey]) {
  38. stack.push(children[activeKey].setActive(true));
  39. }
  40. return Promise.all(stack);
  41. }
  42. }
  43. });