index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import baseComponent from '../helpers/baseComponent'
  2. import classNames from '../helpers/classNames'
  3. baseComponent({
  4. relations: {
  5. '../sticky-item/index': {
  6. type: 'child',
  7. observer() {
  8. this.debounce(this.updated)
  9. },
  10. },
  11. },
  12. properties: {
  13. prefixCls: {
  14. type: String,
  15. value: 'wux-sticky',
  16. },
  17. scrollTop: {
  18. type: Number,
  19. value: 0,
  20. observer: 'onScroll',
  21. },
  22. },
  23. computed: {
  24. classes() {
  25. const { prefixCls } = this.data
  26. const wrap = classNames(prefixCls)
  27. return {
  28. wrap,
  29. }
  30. },
  31. },
  32. methods: {
  33. onScroll(scrollTop = this.data.scrollTop) {
  34. const elements = this.getRelationNodes('../sticky-item/index')
  35. if (elements.length > 0) {
  36. elements.forEach((element, index) => {
  37. element.onScroll(scrollTop)
  38. })
  39. }
  40. },
  41. updated() {
  42. const elements = this.getRelationNodes('../sticky-item/index')
  43. if (elements.length > 0) {
  44. elements.forEach((element, index) => {
  45. element.updated(index)
  46. })
  47. }
  48. },
  49. },
  50. })