index.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. "use strict";
  2. var _component = require("../common/component");
  3. (0, _component.VantComponent)({
  4. relation: {
  5. name: "sidebar-item",
  6. type: "descendant",
  7. current: "sidebar",
  8. linked: function linked() {
  9. this.setActive(this.data.activeKey);
  10. },
  11. unlinked: function unlinked() {
  12. this.setActive(this.data.activeKey);
  13. }
  14. },
  15. props: {
  16. activeKey: {
  17. type: Number,
  18. value: 0,
  19. observer: "setActive"
  20. }
  21. },
  22. beforeCreate: function beforeCreate() {
  23. this.currentActive = -1;
  24. },
  25. methods: {
  26. setActive: function setActive(activeKey) {
  27. var children = this.children,
  28. currentActive = this.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. });