index.js 695 B

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