index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import baseComponent from '../helpers/baseComponent'
  2. import classNames from '../helpers/classNames'
  3. baseComponent({
  4. relations: {
  5. '../index/index': {
  6. type: 'parent',
  7. },
  8. },
  9. properties: {
  10. prefixCls: {
  11. type: String,
  12. value: 'wux-index-item',
  13. },
  14. name: {
  15. type: String,
  16. value: '',
  17. },
  18. },
  19. data: {
  20. index: 0,
  21. top: 0,
  22. height: 0,
  23. },
  24. computed: {
  25. classes() {
  26. const { prefixCls } = this.data
  27. const wrap = classNames(prefixCls)
  28. const hd = `${prefixCls}__hd`
  29. const bd = `${prefixCls}__bd`
  30. return {
  31. wrap,
  32. hd,
  33. bd,
  34. }
  35. },
  36. },
  37. methods: {
  38. updated(index) {
  39. const className = `.${this.data.prefixCls}`
  40. wx
  41. .createSelectorQuery()
  42. .in(this)
  43. .select(className)
  44. .boundingClientRect((rect) => {
  45. if (!rect) return
  46. this.setData({
  47. top: rect.top,
  48. height: rect.height,
  49. index,
  50. })
  51. })
  52. .exec()
  53. },
  54. },
  55. })