index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { VantComponent } from '../common/component';
  2. VantComponent({
  3. relation: {
  4. name: 'collapse-item',
  5. type: 'descendant',
  6. current: 'collapse',
  7. },
  8. props: {
  9. value: {
  10. type: null,
  11. observer: 'updateExpanded'
  12. },
  13. accordion: {
  14. type: Boolean,
  15. observer: 'updateExpanded'
  16. },
  17. border: {
  18. type: Boolean,
  19. value: true
  20. }
  21. },
  22. methods: {
  23. updateExpanded() {
  24. this.children.forEach((child) => {
  25. child.updateExpanded();
  26. });
  27. },
  28. switch(name, expanded) {
  29. const { accordion, value } = this.data;
  30. if (!accordion) {
  31. name = expanded
  32. ? (value || []).concat(name)
  33. : (value || []).filter((activeName) => activeName !== name);
  34. }
  35. else {
  36. name = expanded ? name : '';
  37. }
  38. this.$emit('change', name);
  39. this.$emit('input', name);
  40. }
  41. }
  42. });