index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const itemHeight = 56 * 2;
  2. Component({
  3. data: {
  4. childBoxHeight: 0,
  5. },
  6. externalClasses: ['t-class'],
  7. properties: {
  8. defaultOpen: {
  9. type: Boolean,
  10. value: false,
  11. },
  12. name: {
  13. type: String,
  14. value: '',
  15. },
  16. tag: {
  17. type: String,
  18. value: '',
  19. },
  20. root: {
  21. type: String,
  22. value: '',
  23. },
  24. childArr: {
  25. type: Array,
  26. value: [],
  27. observer(childArr) {
  28. this.setData({
  29. childBoxHeight: this.data.defaultOpen ? itemHeight * childArr.length : 0,
  30. });
  31. },
  32. },
  33. },
  34. methods: {
  35. switchHandle() {
  36. const { childArr, childBoxHeight } = this.data;
  37. this.setData({
  38. childBoxHeight: childBoxHeight > 0 ? 0 : childArr.length * itemHeight,
  39. });
  40. },
  41. tapChild(e) {
  42. this.triggerEvent('click', {
  43. ...e.target.dataset,
  44. root: this.data.root
  45. });
  46. },
  47. },
  48. });