uni-collapse.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <view class="uni-collapse">
  3. <slot />
  4. </view>
  5. </template>
  6. <script>
  7. /**
  8. * Collapse 折叠面板
  9. * @description 展示可以折叠 / 展开的内容区域
  10. * @tutorial https://ext.dcloud.net.cn/plugin?id=23
  11. * @property {Boolean} accordion = [true|false] 是否开启手风琴效果是否开启手风琴效果
  12. * @event {Function} change 切换面板时触发,activeNames(Array):展开状态的uniCollapseItem的 name 值
  13. */
  14. export default {
  15. name: 'UniCollapse',
  16. props: {
  17. accordion: {
  18. // 是否开启手风琴效果
  19. type: [Boolean, String],
  20. default: false
  21. }
  22. },
  23. data() {
  24. return {}
  25. },
  26. provide() {
  27. return {
  28. collapse: this
  29. }
  30. },
  31. created() {
  32. this.childrens = []
  33. },
  34. methods: {
  35. onChange() {
  36. let activeItem = []
  37. this.childrens.forEach((vm, index) => {
  38. if (vm.isOpen) {
  39. activeItem.push(vm.nameSync)
  40. }
  41. })
  42. this.$emit('change', activeItem)
  43. }
  44. }
  45. }
  46. </script>
  47. <style scoped>
  48. .uni-collapse {
  49. /* #ifndef APP-NVUE */
  50. width: 100%;
  51. display: flex;
  52. /* #endif */
  53. /* #ifdef APP-NVUE */
  54. flex: 1;
  55. /* #endif */
  56. flex-direction: column;
  57. background-color: #ffffff;
  58. }
  59. </style>