index.js 1.2 KB

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