collapse.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <div class="nut-collapse" @changeEvt="changeEvt">
  3. <slot></slot>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: 'nut-collapse',
  9. model: {
  10. prop: 'value',
  11. event: 'change-active'
  12. },
  13. props: {
  14. value: {
  15. type: String | Number
  16. },
  17. accordion: {
  18. type: Boolean
  19. },
  20. expandIconPosition: {
  21. type: String,
  22. default: 'right'
  23. },
  24. icon: {
  25. type: String,
  26. default: ''
  27. },
  28. rotate: {
  29. type: Number | String,
  30. default: 180
  31. }
  32. },
  33. watch: {
  34. value(newVal, oldVal) {
  35. this.accordionFun(newVal);
  36. }
  37. },
  38. data() {
  39. return {};
  40. },
  41. methods: {
  42. changeEvt(name) {
  43. this.$parent.change(name);
  44. },
  45. changeValAry(name) {
  46. let index = -1;
  47. this.value.forEach((item, idx) => {
  48. if (String(item) == String(name)) {
  49. index = idx;
  50. }
  51. });
  52. let v = JSON.parse(JSON.stringify(this.value));
  53. index > -1 ? v.splice(index, 1) : v.push(name);
  54. this.$emit('change-active', v);
  55. },
  56. changeVal(val) {
  57. this.$emit('change-active', val);
  58. },
  59. // 手风琴模式将所有的item收起,然后对应的展开(默认)
  60. // 对于展开的再次点击的将其设置成收起,动画效果在item组件中执行
  61. accordionFun(val) {
  62. if (val instanceof Array) {
  63. } else {
  64. this.$children.forEach(item => {
  65. if (item.name == val && item.openExpanded) {
  66. item.changeOpen(false);
  67. } else {
  68. item.name == val ? item.changeOpen(true) : item.changeOpen(false);
  69. item.animation();
  70. }
  71. });
  72. }
  73. }
  74. }
  75. };
  76. </script>