index.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <template>
  2. <uni-shadow-root class="vant-sidebar-index"><view class="van-sidebar custom-class">
  3. <slot></slot>
  4. </view></uni-shadow-root>
  5. </template>
  6. <script>
  7. global['__wxRoute'] = 'vant/sidebar/index'
  8. import { VantComponent } from '../common/component';
  9. VantComponent({
  10. relation: {
  11. name: 'sidebar-item',
  12. type: 'descendant',
  13. current: 'sidebar',
  14. linked() {
  15. this.setActive(this.data.activeKey);
  16. },
  17. unlinked() {
  18. this.setActive(this.data.activeKey);
  19. },
  20. },
  21. props: {
  22. activeKey: {
  23. type: Number,
  24. value: 0,
  25. observer: 'setActive',
  26. },
  27. },
  28. beforeCreate() {
  29. this.currentActive = -1;
  30. },
  31. methods: {
  32. setActive(activeKey) {
  33. const { children, currentActive } = this;
  34. if (!children.length) {
  35. return Promise.resolve();
  36. }
  37. this.currentActive = activeKey;
  38. const stack = [];
  39. if (currentActive !== activeKey && children[currentActive]) {
  40. stack.push(children[currentActive].setActive(false));
  41. }
  42. if (children[activeKey]) {
  43. stack.push(children[activeKey].setActive(true));
  44. }
  45. return Promise.all(stack);
  46. },
  47. },
  48. });
  49. export default global['__wxComponents']['vant/sidebar/index']
  50. </script>
  51. <style platform="mp-weixin">
  52. @import '../common/index.css';.van-sidebar{width:85px;width:var(--sidebar-width,85px)}
  53. </style>