dropmenu.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // components/dropmenu/dropmenu.ts
  2. Component<
  3. {
  4. // heightStyle: string
  5. },
  6. {
  7. // scrollMaxHeight: ComponentPropertyNumberType
  8. },
  9. {
  10. updateChildren(activeIdx: number): void
  11. },
  12. {
  13. children: CustomComponent[]
  14. currentActive: number
  15. }
  16. >({
  17. relations: {
  18. './dropmenu-item': {
  19. type: 'child',
  20. linked(child: CustomComponent) {
  21. this.children.push(child)
  22. },
  23. unlinked(child: CustomComponent) {
  24. this.children = this.children.filter((item) => item !== child)
  25. },
  26. },
  27. './dropmenu-btn': {
  28. type: 'child',
  29. },
  30. },
  31. options: {
  32. addGlobalClass: true,
  33. multipleSlots: true,
  34. },
  35. externalClasses: ['n-class'],
  36. /**
  37. * 组件的属性列表
  38. */
  39. properties: {},
  40. /**
  41. * 组件的初始数据
  42. */
  43. data: {},
  44. /**
  45. * 组件的方法列表
  46. */
  47. methods: {
  48. updateChildren(activeIdx: number) {
  49. const { children } = this
  50. if (children && children.length > 0) {
  51. children.forEach((child, idx) => {
  52. child.setShow(idx === activeIdx)
  53. })
  54. }
  55. return Promise.resolve()
  56. },
  57. },
  58. lifetimes: {
  59. created() {
  60. this.children = []
  61. },
  62. },
  63. })