index.js 839 B

12345678910111213141516171819202122232425262728293031323334
  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. current: 'sidebar-item',
  11. },
  12. props: {
  13. dot: Boolean,
  14. info: null,
  15. title: String,
  16. disabled: Boolean
  17. },
  18. methods: {
  19. onClick() {
  20. const { parent } = this;
  21. if (!parent || this.data.disabled) {
  22. return;
  23. }
  24. const index = parent.children.indexOf(this);
  25. parent.setActive(index).then(() => {
  26. this.$emit('click', index);
  27. parent.$emit('change', index);
  28. });
  29. },
  30. setActive(selected) {
  31. return this.setData({ selected });
  32. }
  33. }
  34. });