index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { VantComponent } from '../common/component';
  2. VantComponent({
  3. relation: {
  4. name: 'collapse-item',
  5. type: 'descendant',
  6. linked: function linked(child) {
  7. this.set({
  8. items: this.data.items.concat([child])
  9. }, function () {
  10. child.updateExpanded();
  11. });
  12. }
  13. },
  14. props: {
  15. accordion: Boolean,
  16. value: null
  17. },
  18. data: {
  19. items: []
  20. },
  21. watch: {
  22. value: function value() {
  23. this.data.items.forEach(function (child) {
  24. child.updateExpanded();
  25. });
  26. },
  27. accordion: function accordion() {
  28. this.data.items.forEach(function (child) {
  29. child.updateExpanded();
  30. });
  31. }
  32. },
  33. methods: {
  34. switch: function _switch(name, expanded) {
  35. var _this$data = this.data,
  36. accordion = _this$data.accordion,
  37. value = _this$data.value;
  38. if (!accordion) {
  39. name = expanded ? value.concat(name) : value.filter(function (activeName) {
  40. return activeName !== name;
  41. });
  42. } else {
  43. name = expanded ? name : '';
  44. }
  45. this.$emit('change', name);
  46. this.$emit('input', name);
  47. }
  48. }
  49. });