index.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <template>
  2. <uni-shadow-root class="weapp-lib-sidebar-index"><view class="van-sidebar custom-class">
  3. <slot></slot>
  4. </view></uni-shadow-root>
  5. </template>
  6. <script>
  7. global['__wxRoute'] = 'weapp/lib/sidebar/index'
  8. "use strict";
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. var component_1 = require("../common/component");
  11. var relation_1 = require("../common/relation");
  12. (0, component_1.VantComponent)({
  13. relation: (0, relation_1.useChildren)('sidebar-item', function () {
  14. this.setActive(this.data.activeKey);
  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. });
  44. export default global['__wxComponents']['weapp/lib/sidebar/index']
  45. </script>
  46. <style platform="mp-weixin">
  47. @import '../common/index.css';.van-sidebar{width:var(--sidebar-width,80px)}
  48. </style>