index.ts 796 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // components/horbar/index.ts
  2. Component({
  3. options: {
  4. multipleSlots: true,
  5. addGlobalClass: true,
  6. },
  7. /**
  8. * 组件的属性列表
  9. */
  10. properties: {
  11. items: {
  12. type: Array,
  13. value: [],
  14. },
  15. active: {
  16. type: Number,
  17. value: 0,
  18. observer(val: number) {
  19. this.setData({
  20. activeIndex: val,
  21. })
  22. },
  23. },
  24. },
  25. /**
  26. * 组件的初始数据
  27. */
  28. data: {
  29. activeIndex: 0,
  30. },
  31. /**
  32. * 组件的方法列表
  33. */
  34. methods: {
  35. onClick(e: WechatMiniprogram.TouchEvent<{}, {}, { idx: number }>) {
  36. const { idx } = e.currentTarget.dataset
  37. this.setData({
  38. activeIndex: idx,
  39. })
  40. this.triggerEvent('change', {
  41. idx,
  42. item: this.data.items[idx],
  43. })
  44. },
  45. },
  46. })