index.js 875 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { VantComponent } from '../common/component';
  2. VantComponent({
  3. classes: [
  4. 'active-class',
  5. 'disabled-class',
  6. ],
  7. relation: {
  8. type: 'ancestor',
  9. name: 'sidebar',
  10. linked(target) {
  11. this.parent = target;
  12. }
  13. },
  14. props: {
  15. dot: Boolean,
  16. info: null,
  17. title: String,
  18. disabled: Boolean
  19. },
  20. methods: {
  21. onClick() {
  22. const { parent } = this;
  23. if (!parent || this.data.disabled) {
  24. return;
  25. }
  26. const index = parent.children.indexOf(this);
  27. parent.setActive(index).then(() => {
  28. this.$emit('click', index);
  29. parent.$emit('change', index);
  30. });
  31. },
  32. setActive(selected) {
  33. return this.setData({ selected });
  34. }
  35. }
  36. });