index.js 1.3 KB

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