index.js 712 B

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