index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var component_1 = require("../common/component");
  4. component_1.VantComponent({
  5. relation: {
  6. name: 'collapse-item',
  7. type: 'descendant',
  8. linked: function (child) {
  9. this.children.push(child);
  10. },
  11. unlinked: function (child) {
  12. this.children = this.children.filter(function (item) { return item !== child; });
  13. }
  14. },
  15. props: {
  16. value: {
  17. type: null,
  18. observer: 'updateExpanded'
  19. },
  20. accordion: {
  21. type: Boolean,
  22. observer: 'updateExpanded'
  23. },
  24. border: {
  25. type: Boolean,
  26. value: true
  27. }
  28. },
  29. beforeCreate: function () {
  30. this.children = [];
  31. },
  32. methods: {
  33. updateExpanded: function () {
  34. this.children.forEach(function (child) {
  35. child.updateExpanded();
  36. });
  37. },
  38. switch: function (name, expanded) {
  39. var _a = this.data, accordion = _a.accordion, value = _a.value;
  40. if (!accordion) {
  41. name = expanded
  42. ? (value || []).concat(name)
  43. : (value || []).filter(function (activeName) { return activeName !== name; });
  44. }
  45. else {
  46. name = expanded ? name : '';
  47. }
  48. this.$emit('change', name);
  49. this.$emit('input', name);
  50. }
  51. }
  52. });