index.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <uni-shadow-root class="vant-collapse-index"><view :class="'custom-class van-collapse '+(border ? 'van-hairline--top-bottom' : '')">
  3. <slot></slot>
  4. </view></uni-shadow-root>
  5. </template>
  6. <script>
  7. global['__wxRoute'] = 'vant/collapse/index'
  8. import { VantComponent } from '../common/component';
  9. VantComponent({
  10. relation: {
  11. name: 'collapse-item',
  12. type: 'descendant',
  13. current: 'collapse',
  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. methods: {
  30. updateExpanded() {
  31. this.children.forEach((child) => {
  32. child.updateExpanded();
  33. });
  34. },
  35. switch(name, expanded) {
  36. const { accordion, value } = this.data;
  37. const changeItem = name;
  38. if (!accordion) {
  39. name = expanded
  40. ? (value || []).concat(name)
  41. : (value || []).filter((activeName) => activeName !== name);
  42. } else {
  43. name = expanded ? name : '';
  44. }
  45. if (expanded) {
  46. this.$emit('open', changeItem);
  47. } else {
  48. this.$emit('close', changeItem);
  49. }
  50. this.$emit('change', name);
  51. this.$emit('input', name);
  52. },
  53. },
  54. });
  55. export default global['__wxComponents']['vant/collapse/index']
  56. </script>
  57. <style platform="mp-weixin">
  58. @import '../common/index.css';
  59. </style>