index.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. const changeItem = name;
  31. if (!accordion) {
  32. name = expanded
  33. ? (value || []).concat(name)
  34. : (value || []).filter((activeName) => activeName !== name);
  35. } else {
  36. name = expanded ? name : '';
  37. }
  38. if (expanded) {
  39. this.$emit('open', changeItem);
  40. } else {
  41. this.$emit('close', changeItem);
  42. }
  43. this.$emit('change', name);
  44. this.$emit('input', name);
  45. },
  46. },
  47. });