index.js 817B

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